How to declare global variables for simulink containing matlab functions?

user10678 picture user10678 · May 26, 2015 · Viewed 11.9k times · Source

I'm building a simulink model with multiple matlab function blocks( http://in.mathworks.com/help/simulink/slref/matlabfunction.html ). Each of these function blocks have a lot of constants, for example (g=9.8), common between them. I want to initialize all of these constants in one go so that I don't have to do so in each function block.

I tried initialising all the variables in matlab workspace, but they don't seem to be working.

What is the best and easiest way to go forward with this?

Answer

Mohsen Nosratinia picture Mohsen Nosratinia · May 26, 2015

You need to either define your global variables as Simulink.Signal object or a Data Store Memory block and then define them as global in your MATLAB function. You cannot access the regular MATLAB variables from MATLAB workspace.

There is a detailed page about this on MAthworks website with a good example.