Reputation: 159
I'm building a Simulink model with multiple Matlab function blocks. Each of these function blocks has 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 initializing 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?
Upvotes: 5
Views: 21748
Reputation: 14008
The canonical method for adding variables/constants across your Simulink model is to use the Model Explorer from the MODELING tab or by pressing Ctrl+H:
select either the Base Workspace or the ModelWorkspace
from the Meubar select Add and then select the MATLAB Variable or press Ctrl+M.
change the variable name by double-clicking it in the table and its value on the right panel:
Upvotes: 1
Reputation: 9864
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.
Upvotes: 5