Documentation Center

  • Trial Software
  • Product Updates

Specify Parameter Values

About Parameter Values

Many block parameters, including mathematical parameters, accept MATLAB® expression strings as values. When Simulink® compiles a model, for example, at the start of a simulation or when you update the model, Simulink sets the compiled values of the parameters to the result of evaluating the expressions.

Use Workspace Variables in Parameter Expressions

Block parameter expressions can include variables defined in the model's mask and model workspaces and in the MATLAB workspace. Using a workspace variable facilitates updating a model that sets multiple block parameters to the same value, i.e., it allows you to update multiple parameters by setting the value of a single workspace variable. For more information, see Symbol Resolution and Numeric Values with Symbols.

Using a workspace variable also allows you to change the value of a parameter during simulation without having to open a block's parameter dialog box. For more information, see Tunable Parameters.

    Note:   If you have a Simulink Coder™ license, and you plan to generate code from a model, you can use workspace variables to specify the name, data type, scope, volatility, tunability, and other attributes of variables used to represent the parameter in the generated code. For more information, see Parameters in the Simulink Coder documentation.

Resolve Variable References in Block Parameter Expressions

When evaluating a block parameter expression that contains a variable, Simulink by default searches the workspace hierarchy. If the variable is not defined in any workspace, Simulink halts compilation of the model and displays an error message. See Symbol Resolution and Numeric Values with Symbols for more information.

Use Parameter Objects to Specify Parameter Values

You can use Simulink.Parameter objects in parameter expressions to specify parameter values. For example, K and 2*K are both valid parameter expressions where K is a workspace variable that references a Simulink.Parameter object. In both cases, Simulink uses the parameter object's Value property as the value of K.

You cannot use arrays of Simulink.Parameter objects as block parameters.

See Symbol Resolution and Numeric Values with Symbols for more information.

Using parameter objects to specify parameters can facilitate tuning parameters in some applications. See Using a Parameter Object to Specify a Parameter As Noninline and Parameterize Model References for more information.

    Note:   Do not use expressions of the form p.Value where p is a parameter object in block parameter expressions. Such expressions cause evaluation errors when Simulink compiles the model.

Convert Numeric Variable into Simulink.Parameter Object

You can convert a numeric variable into a Simulink.Parameter object as follows.

myVar = 5; /* Define numerical variable in base workspace
myObject = Simulink.Parameter; /* Create data object
myObject.Value = myVar; /* Assign variable value to data object value

Determine Parameter Data Types

When Simulink compiles a model, each of the model's blocks determines a data type for storing the values of its parameters whose values are specified by MATLAB parameter expressions.

Most blocks use internal rules to determine the data type assigned to a specific parameter. Exceptions include the Gain block, whose parameter dialog box allows you to specify the data type assigned to the compiled value of its Gain parameter. You can configure your model to check whether the data type assigned to a parameter can accommodate the parameter value specified by the model (see Data Validity Diagnostics Overview).

Obtain Parameter Information

You can use get_param to find the system and block parameter values for your model. See Model Parameters and Common Block Properties for arguments get_param accepts.

The model's signal attributes and parameter expressions must be evaluated before some parameters are properly reported. This evaluation occurs during the simulation compilation phase. Alternatively, you can compile your model without first running it, and then obtain parameter information. For instance, to access the port width, data types, and dimensions of the blocks in your model, enter the following at the command prompt:

Was this topic helpful?