| Contents | Index |
| On this page… |
|---|
Using Workspace Variables in Parameter Expressions Resolving Variable References in Block Parameter Expressions |
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.
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 Resolving Symbols and Specifying 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 Using Tunable Parameters.
Note If 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. |
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 Resolving Symbols and Specifying Numeric Values with Symbols for more information.
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. See Resolving Symbols and Specifying Numeric Values with Symbolsfor 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 Noninlined and Parameterizing 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. |
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).
You can use get_param to find the system and block parameter values for your model. See Model and Block Parameters for a list of 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:
modelname([],[],[],'compile') q=get_param(gcb,'PortHandles'); get_param(q.Inport,'CompiledPortDataType') get_param(q.Inport,'CompiledPortWidth') get_param(q.Inport,'CompiledPortDimensions') modelname([],[],[],'term')
![]() | Setting Block Parameters | Checking Parameter Values | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |