A parameterized referenced model obtains values that affect the behavior of the referenced model from some source outside the model. Changing the values changes the behavior of the model, without recompiling the model.
Simulink® provides two techniques that you can use to parameterize referenced models:
Global parameters work the same way with referenced models that they do with any other model construct. Each global parameter has the same value in every instance of a referenced model that uses it. Model arguments allow you to provide different values to each instance of a referenced model. Each instance can then behave differently from the others. The effect is analogous to calling a function more than once with different arguments in each call.
You can use a structure parameter to group variables for parameterizing model references. For details, see Organize Related Block Parameter Definitions in Structures.
A global parameter is a numeric MATLAB® variable
The parameter exists in the MATLAB base workspace or in a Simulink data
Using a global parameter in a referenced model allows you to control the behavior of the referenced model by setting the parameter value. All instances of the model use the same value. You can change the value during simulation or between one simulation and the next. The change does not require rebuilding the model in which the change occurs, or any models that it references. See Tune and Experiment with Block Parameter Values for details.
If you have a Simulink Coder™ license, a MATLAB variable
Simulink.Parameter object that you can tune
during simulation can appear in the generated code as an inlined,
nontunable numeric value. To create global tunable parameters in the
generated model reference code, see Tunable Parameters in the Generated Code for Referenced Models.
Model arguments let you parameterize references to the same model so that each instance of the model behaves differently. Without model arguments, a variable in a referenced model has the same value in every instance of the model. Declaring a variable to be a model argument allows each instance of the model to use a different value for that variable.
To create model arguments for a referenced model:
Create MATLAB variables in the model workspace.
Add the variables to a list of model arguments associated with the model.
Specify values for those variables separately in each Model block that references the model.
The values that you specify in the Model block replace the values of the MATLAB variables for that instance of the model.
A referenced model that uses model arguments can also appear as a top model or a standalone model. No Model block exists to provide model argument values. That model uses the values of the MATLAB variables as defined in the model workspace. You can use the same model, without changing it, as a top model, a standalone model, and a parameterized referenced model.
demonstrates techniques for using model arguments. The model passes
model argument values to referenced models through masked Model blocks.
Masking can be convenient but is independent of the definition and
use of model arguments themselves. See Block Masks for
information about masking.
The rest of this section describes techniques for declaring and using model arguments to parameterize a referenced model independently of any Model block masking. The steps are:
Create MATLAB variables in the model workspace.
Register the variables as model arguments.
Assign values to those arguments in Model blocks.
Open the Model Explorer. In the Simulink Editor, select View > Model Explorer > Model Explorer.
In the Model Explorer Model Hierarchy pane, select the Model Workspace node for the model.
From Model Explorer Add menu, select MATLAB Variable twice.
Select another node and then reselect Model Workspace node. Two new MATLAB variables appear in the Contents pane with a default name and value.
In the Contents pane
change the name of the two variables. Change
In the Model Explorer Model Hierarchy pane, select the workspace of the model.
The Dialog pane displays the Model Workspace dialog box.
In the Model
arguments field, enter the names of the MATLAB variables
to use as model arguments (
using a comma-separated list.
Click Apply to confirm the entered names.
If a model declares model arguments, assign values to those
arguments in each Model block that references the model. Failing to
assign a value to a model argument causes an error. The value of the
model argument does not default to the value
of the corresponding MATLAB variable. That value is available
only to a standalone or top model. This example assigns values to
the arguments of the model referenced by the
Select the Model and open its block parameters dialog box.
The Model arguments field displays the same MATLAB variables, in the same order, that appear in the Model arguments field of the Model Workspace dialog box. The Model block field Model arguments is not editable. It indicates the model arguments that you need to assign values to, and the order of the arguments.
In the Model argument values field, enter a comma-delimited list of values for the model arguments that appear in the Model arguments field. Simulink assigns the values to arguments in positional order, so they must appear in the same order as the corresponding arguments.
You can enter literal values, variable names, MATLAB expressions,
Simulink.Parameter objects. Any symbols used
resolve to values as described in Symbol Resolution Process.
All values must be numeric (including objects with numeric values).
Note: Do not use a model argument in an expression that is nontunable because of the issues documented in Tunable Expression Limitations.
The value for each argument must have the same dimensions and complexity as the MATLAB variable that defines the model argument in the model workspace. The data types need not match. If necessary, the Simulink software casts a model argument value to the data type of the corresponding variable.
Click OK or Apply to confirm the values for the Model block.
When the model executes in the context of that Model block, the Model arguments have the values specified in the Model argument values field of the Model block.