| Simulink® | ![]() |
| On this page… |
|---|
Creating the MATLAB® Variables |
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, you create MATLAB® variables in the model workspace, then add the variables to a list of model arguments associated with the model. You can then specify values for those variables separately in each Model block that references the model. The values specified in the Model block replace the values of the MATLAB variables for that instance of the model.
A referenced model that uses model arguments might also appear as a top model or a standalone model. No Model block then exists to provide model argument values, and the model uses the values of the MATLAB variables themselves, as defined in the model workspace. Thus the same model can be used without change as a top model, a standalone model, and a parameterized referenced model.
The demo model sldemo_mdlref_paramargs demonstrates techniques for using model arguments. The demo passes model argument values to referenced models through masked Model blocks. Such masking can be convenient, but is independent of the definition and use of model arguments themselves. See Creating Block Masks for details 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 to be model arguments.
Assign values to those arguments in Model blocks.
To create MATLAB variables that will be used as model arguments:
Open the model for which you want to define model arguments.
Select the model's workspace in Model Explorer's Model Hierarchy pane:

From Model Explorer's Add menu, select MATLAB Variable.
A new MATLAB variable appears in the Contents pane with a default name and value.
In the Contents pane:
Change the default name of the new MATLAB variable to a name that you want to declare as a model argument.
If you will also use the model as a top or standalone model, specify the value that the variable should have in that context. This value must be numeric.
If the variable type does not match the dimensions and complexity of the model argument, specify a value that has the correct type. This type must be numeric.
Repeat adding and naming MATLAB variables until you have defined all the variables that you need.
To register MATLAB variables as model arguments:
Again select the model's workspace in Model Explorer's Model Hierarchy pane.
The Dialog pane displays the Model Workspace dialog.
In the Model Workspace dialog, enter the names of the MATLAB variables that you want to declare as model arguments as a comma-separated list in the Model arguments field.
For example, if you added two MATLAB variables named init_value and incr, and declared them to be model arguments, the Contents and Dialog panes of the Model Explorer could look like this:

If a model declares model arguments, you must 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. To assign values to a referenced model's arguments:
Open the Model block's parameter dialog box by right-clicking the block and choosing Model Reference Parameters from the context menu.

The second field, Model arguments, specifies the same MATLAB variables, in the same order, that you previously typed into the Model arguments field of the Model Workspace dialog. This field cannot be edited. It provides a reminder of which model arguments need values assigned, and in what order.
In the Model argument values field, enter a comma-delimited list of values for the model arguments that appear in the Model arguments field. The values are assigned to arguments in positional order, so they must appear in the same order as the corresponding arguments.

You can enter the values as literal values, variable names, MATLAB expressions, and Simulink® parameter objects. Any symbols used resolve to values as described in Hierarchical Symbol Resolution. All values must be numeric (including objects with numeric values).
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 will cast a model argument value to the data type of the corresponding MATLAB 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 will have the values specified in the Model block's Model argument values field.
![]() | Parameterizing Model References | Refreshing Model Blocks | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |