Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Parameterizing Model References

Introduction

A parameterized referenced model obtains values that affect the referenced model's behavior from some source outside the model. Changing the values changes the behavior of the model without requiring the model to be recompiled.

Due to the constraints described in Inline Parameter Requirements, you cannot use the Model Parameter Configuration dialog box to parameterize referenced models. The Simulink software provides three other 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.

Global Nontunable Parameters

A global nontunable parameter is a MATLAB variable or a Simulink.Parameter object whose storage class is auto. The parameter can exist in the MATLAB workspace or any model workspace visible to all referenced models that use the parameter.

Using a global nontunable parameter in a referenced model allows you to control the behavior of the referenced model by setting the parameter value before simulation begins. All instances of the model use the same value. You cannot change the value during simulation, but you can change it between one simulation and the next. The change requires rebuilding the model in which the change occurs, but not any models that it references. See Specifying Numeric Parameter Values for details.

Global Tunable Parameters

A global tunable parameter is a Simulink.Parameter object whose storage class is other than auto. The parameter exists in the MATLAB workspace.

Using a global tunable 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 Changing the Values of Block Parameters During Simulation for details.

If you want to reference an existing model that uses tunable parameters defined with the Model Parameter Configuration Dialog Box, you must change the model to implement tunability in some other way. To facilitate this task, Simulink provides a command that converts tunable parameters specified in the Model Parameter Configuration dialog box to global tunable parameters. See tunablevars2parameterobjects for details.

Using Model Arguments

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 can 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 Working with 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:

Creating the MATLAB Variables

To create MATLAB variables that will be used as model arguments:

  1. Open the model for which you want to define model arguments.

  2. Open the Model Explorer.

  3. Select the model's workspace in Model Explorer's Model Hierarchy pane:

  4. From Model Explorer's Add menu, select MATLAB Variable.

    A new MATLAB variable appears in the Contents pane with a default name and value.

  5. In the Contents pane:

    1. Change the default name of the new MATLAB variable to a name that you want to declare as a model argument.

    2. If you 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.

    3. 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.

  6. Repeat adding and naming MATLAB variables until you have defined all the variables that you need.

Registering the Model Arguments

To register MATLAB variables as model arguments:

  1. Again select the model's workspace in Model Explorer's Model Hierarchy pane.

    The Dialog pane displays the Model Workspace dialog.

  2. 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:

  3. Click Apply to confirm the entered names.

Assigning Model Argument Values

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:

  1. 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 is not editable. It provides a reminder of which model arguments need values assigned, and in what order.

  2. 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 casts a model argument value to the data type of the corresponding variable.

  3. 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS