Manage Model Data
To define a parameter value that multiple blocks or models use, you can use variables. Separately updating numerical parameter values at each instance of the parameter can be inefficient and error-prone. You can update the value of a variable in the workspace or source file that defines the variable. Having a single source for this information facilitates scalability and reusability of model components.
To specify value ranges, data types, tunability, and other characteristics of signals, states, and block parameters, you can use Simulink.Parameter
and Simulink.Signal
objects. While you can use variables or objects to specify parameter values, this example uses variables for simplicity.
You can define variables by using these supporting file types:
MAT file (
.mat
)Script or function (
.m
)Data dictionary (
.sldd
)
To load data for small models, you can use model callbacks. For large model hierarchies, other loading methods are more efficient.
When you open the model named BasicModelingData
, the PreLoadFcn
model callback evaluates a script that defines variables in the base workspace.
mdl = "BasicModelingData"; open_system(mdl); cb = get_param(gcs,"PreLoadFcn")
cb = 'BasicModelingDataDefinitions'
In the plant, Gain blocks use the variables named k
, c
, and m
. Each Gain block icon displays a variable used by the block.
In the controller, PID Controller blocks use the other variables from the script, such as kpHeight
and kiHeight
. When you select a PID Controller block, the Property Inspector displays the variables the block uses.
To interactively change variable values, use the MATLAB® Command Window, Model Data Editor, or a similar tool.