| Simulink® | ![]() |
| On this page… |
|---|
Mathematical Versus Configuration Parameters Specifying Numeric Parameter Values |
All Simulink® blocks have attributes that you can specify. Some user-specifiable attributes are common to all Simulink blocks, for example, a block's name and foreground color. Other attributes are specific to a block, for example, the gain of a Gain block. Simulink associates a variable, called a block parameter, with each user-specifiable attribute of a block. You specify the attribute by setting its associated parameter to a corresponding value. For example, to set the foreground color of a block to red, you set the value of its foreground color parameter to the string 'red'. The Simulink parameter reference lists the names, usages, and valid settings for Simulink block parameters (see Common Block Parameters and Block-Specific Parameters).
Block parameters fall into two broad categories. A mathematical parameter is a parameter used to compute the value of a block's output, for example, the Gain parameter of a Gain block. All other parameters are configuration parameters, for example, a Gain block's Name parameter. In general, you can change the values of mathematical but not configuration parameters during simulation (see Changing the Values of Block Parameters During Simulation).
You can use the Simulink set_param command to set the value of any Simulink block parameter. In addition, you can set many block parameters via Simulink dialog boxes and menus. These include:
Format menu
The Model Editor's Format menu allows you to specify attributes of the currently selected block that are visible on the model's block diagram, such as the block's name and color (see Changing a Block's Appearance for more information).
Block Properties dialog box
Specifies various attributes that are common to all blocks (see Block Properties Dialog Box for more information).
Block Parameter dialog box
Every block has a dialog box that allows you to specify values for attributes that are specific to that type of block. See Displaying a Block's Parameter Dialog Box for information on displaying a block's parameter dialog box. For information on the parameter dialog of a specific block, see Blocks — Alphabetical List in the online Simulink reference.
Model Explorer
The Model Explorer allows you to quickly find one or more blocks and set their properties, thus facilitating global changes to a model, for example, changing the gain of all of a model's Gain blocks. See The Model Explorer for more information.
To display a block's parameter dialog box, double-click the block in the model or library window. You can also display a block's parameter dialog box by selecting the block in the model's block diagram and choosing BLOCK Parameters from the model window's Edit menu or from the block's context (right-click) menu, where BLOCK is the name of the block you selected, e.g., Constant Parameters.
Note Double-clicking a block to display its parameter dialog box works for all blocks with parameter dialog boxes except for Subsystem blocks. You must use the Model Editor's Edit menu or the block's context menu to display a Subsystem block's parameter dialog box. |
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 Changing the Values of Block Parameters During Simulation.
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 Parameter Storage, Interfacing, and Tuning in the Real-Time Workshop® 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. For more information, see Resolving Symbols and Specifying Numeric Values with Symbols.
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 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).
Obtaining Parameter Information. 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')
Several blocks perform range checking of their mathematical parameters. Generally, blocks that allow you to enter minimum and maximum values check to ensure that the values of applicable parameters lie within the specified range. See the following topics for more information:
The following blocks perform range checking for their parameters:
| Block | Parameters Checked |
|---|---|
Constant value | |
Initial value | |
Gain | |
Table data | |
Table data | |
Table data | |
Table data | |
Output when on | |
Vector of output values | |
Vector of output values | |
Upper limit |
In general, use the Output minimum and Output maximum parameters that appear on a block parameter dialog box to specify a range of valid values for the block parameters. The following exceptions apply:
For the Gain block, use the Parameter minimum and Parameter maximum fields to specify a range for the Gain parameter.
For the Data Store Memory block, use the Minimum and Maximum fields to specify a range for the Initial value parameter.
When specifying minimum and maximum values that constitute a range, enter only expressions that evaluate to a scalar, real number with double data type. The default value, [], is equivalent to -Inf for the minimum value and Inf for the maximum value. The scalar values that you specify are subject to expansion, for example, when the block parameters that Simulink checks are nonscalar (see Scalar Expansion of Inputs and Parameters).
Note You cannot specify the minimum or maximum value as NaN. |
Specifying Ranges for Complex Numbers. When you specify a minimum or maximum value for a parameter that is a complex number, the specified minimum and maximum apply separately to the real part and to the imaginary part of the complex number. If the value of either part of the number is less than the minimum, or greater than the maximum, the complex number is outside the specified range. No range checking occurs against any combination of the real and imaginary parts, such as (sqrt(a^2+b^2))
You can initiate parameter range checking in the following ways:
When you click the OK or Apply button on a block parameter dialog box, the block performs range checking for its parameters. However, the block checks only the parameters that it can readily evaluate. For example, the block does not check parameters that use an undefined workspace variable.
When you start a simulation or select Update Diagram from the Simulink Edit menu, Simulink performs parameter range checking for all blocks in that model.
Simulink performs parameter range checking by comparing the values of applicable block parameters with both the specified range (see Specifying Ranges for Parameters) and the block data type. That is, Simulink performs the following check:
DataTypeMin ≤ MinValue ≤ VALUE ≤ MaxValue ≤ DataTypeMax
where
DataTypeMin is the minimum value representable by the block data type.
MinValue is the minimum value the block should output, specified by, e.g., Output minimum.
VALUE is the numeric value of a block parameter.
MaxValue is the maximum value the block should output, specified by, e.g., Output maximum.
DataTypeMax is the maximum value representable by the block data type.
When Simulink detects a parameter value that violates the check, it displays an error message. For example, consider a model that contains a Constant block whose
Constant value parameter specifies the variable const, which you have yet to define in a workspace.
Output minimum and Output maximum parameters are set to 2 and 8, respectively.
Output data type parameter is set to uint8.
In this situation, Simulink does not perform parameter range checking when you click the OK button on the Constant block dialog box because the variable const is undefined. But suppose you define its value by entering
const = 10
at the MATLAB prompt, and then you update the diagram (see Updating a Block Diagram). Simulink displays the following error message:

Simulink lets you change the values of many block parameters during simulation. Such parameters are called tunable parameters. In general, only parameters that represent mathematical variables, such as the Gain parameter of the Gain block, are tunable. Parameters that specify the appearance or structure of a block, e.g., the number of inputs of a Sum block, or when it is evaluated, e.g., a block's sample time or priority, are not tunable. You can tell whether a particular parameter is tunable by examining its edit control in the block's dialog box or Model Explorer during simulation. If the control is disabled, the parameter is nontunable.
Note You cannot tune inline parameters. See Inlining Parameters for more information. |
You can use a block's dialog box or the Model Explorer to modify the tunable parameters of any block, except a source block (see Changing Source Block Parameters During Simulation). To use the block's parameter dialog box, open the block's parameter dialog box, change the value displayed in the dialog box, and click the dialog box's OK or Apply button.
You can also tune a parameter at the MATLAB command line, using either the set_param command or by assigning a new value to the MATLAB workspace variable that specifies the parameter's value. In either case, you must update the model's block diagram for the change to take effect (see Updating a Block Diagram).
Opening the dialog box of a source block with tunable parameters (see Source Blocks with Tunable Parameters) causes a running simulation to pause. While the simulation is paused, you can edit the parameter values displayed on the dialog box. However, you must close the dialog box to have the changes take effect and allow the simulation to continue. Similarly, starting a simulation causes any open dialog boxes associated with source blocks with tunable parameters to close.
Note If you enable the Inline parameters option, Simulink does not pause the simulation when you open a source block's dialog box because all of the parameter fields are disabled and can be viewed but cannot be changed. |
The Model Explorer disables the parameter fields that it displays in the list view and the dialog pane for a source block with tunable parameters while a simulation is running. As a result, you cannot use the Model Explorer to change the block's parameters. However, while the simulation is running, the Model Explorer displays a Modify button in the dialog view for the block. Clicking the Modify button opens the block's dialog box. Note that this causes the simulation to pause. You can then change the block's parameters. You must close the dialog box to have the changes take effect and allow the simulation to continue. Your changes appear in the Model Explorer after you close the dialog box.
Source Blocks with Tunable Parameters. Source blocks with tunable parameters include the following blocks.
Simulink source blocks, including
User-developed masked subsystem blocks that have one or more tunable parameters and one or more output ports, but no input ports.
S-Function and M-file (level 2) S-Function blocks that have one or more tunable parameters and one or more output ports but no input ports.
The Inline parameters optimization (see Inline parameters ) controls how mathematical block parameters appear in code generated from the model. When this optimization is off (the default), a model's mathematical block parameters appear as variables in the generated code. As a result, you can tune the parameters both during simulation and when executing the code. When this option is on, the parameters appear in the generated code as inlined numeric constants. This reduces the generated code's memory and processing requirements. However, because the inline parameters appear as constants in the generated code, you cannot tune them during code execution. Furthermore, to ensure that simulation faithfully models the generated code, Simulink prevents you from changing the values of block parameters during simulation when the Inline parameters option is on.
Suppose that you want to take advantage of the Inline parameters optimization while retaining the ability to tune some of your model's parameters. You can do this by declaring some parameters as noninline, using either the Model Parameter Configuration Dialog Box or a Simulink.Parameter object. In either case, you must use a workspace variable to specify the value of the parameter.
Note The documentation for the Real-Time Workshop refers to workspace variables used to specify the value of noninline parameters as tunable workspace parameters. In this context, the term parameter refers to a workspace variable used to specify a parameter as opposed to the parameter itself. |
Note When compiling a model with the inline parameters option on, Simulink checks to ensure that the data types of the workspace variables used to specify the model's noninline parameters are compatible with code generation. If not, Simulink halts the compilation and displays an error. See Tunable Workspace Parameter Data Type Considerations for more information. |
Using a Parameter Object to Specify a Parameter As Noninlined. If you use a parameter object to specify a parameter's value (see Using Parameter Objects to Specify Parameter Values), you can also use the object to specify the parameter as noninlined. To do this, set the parameter object's RTWInfo.StorageClass property to any value but 'Auto' (the default).
K=Simulink.Parameter; K.RTWInfo.StorageClass = 'SimulinkGlobal';
If you set the RTWInfo.StorageClass property to any value other than Auto, you should not include the parameter in the tunable parameters table in the model's Model Parameter Configuration dialog box.
Note Simulink halts model compilation and displays an error message if it detects a conflict between the properties of a parameter as specified by a parameter object and the properties of the parameter as specified in the Model Parameter Configuration dialog box. |
This dialog box lets you set a block's properties. To display this dialog, select the block in the model window and then select Block Properties from the Edit menu.
The dialog box contains the following tabbed panes:
This pane allows you to set the following properties.

Description. Brief description of the block's purpose.
Priority. Execution priority of this block relative to other blocks in the model. See Assigning Block Priorities for more information.
Tag. Text that is assigned to the block's Tag parameter and saved with the block in the model. You can use the tag to create your own block-specific label for a block.
The block annotation pane allows you to display the values of selected block parameters in an annotation that appears beneath the block's icon.

Enter the text of the annotation in the text field that appears on the right side of the pane. The text can include any of the block property tokens that appear in the list on the left side of the pane. A block property token is simply the name of a block parameter preceded by %< and followed by >. When displaying the annotation, the Simulink software replaces the tokens with the values of the corresponding block parameters. For example, suppose that you enter the following text and tokens for a Product block:
Multiplication = %<Multiplication> Sample time = %<SampleTime>
In the model editor window, the annotation appears as follows:

The block property token list on the left side of the pane lists all the parameters that are valid for the currently selected block (see Model and Block Parameters in the Simulink® Reference). To add one of the listed tokens to the text field on the right side of the pane, select the token and then click the button between the list and the text field.
You can also create block annotations programmatically. See Creating Block Annotations Programmatically.
The Callbacks Pane allows you to specify implementations for a block's callbacks (see Using Callback Functions).

To specify an implementation for a callback, select the callback in the callback list on the left side of the pane. Then enter MATLAB commands that implement the callback in the right-hand field. Click OK or Apply to save the change. Simulink appends an asterisk to the name of the saved callback to indicate that it has been implemented.
You can use a block's AttributesFormatString parameter to display selected block parameters beneath the block as an "attributes format string," i.e., a string that specifies values of the block's attributes (parameters). Model and Block Parameters in Simulink® Reference describes the parameters that a block can have. Use the Simulink set_param function to set this parameter to the desired attributes format string.
The attributes format string can be any text string that has embedded parameter names. An embedded parameter name is a parameter name preceded by %< and followed by >, for example, %<priority>. Simulink displays the attributes format string beneath the block's icon, replacing each parameter name with the corresponding parameter value. You can use line-feed characters (\n) to display each parameter on a separate line. For example, specifying the attributes format string
pri=%<priority>\ngain=%<Gain>
for a Gain block displays

If a parameter's value is not a string or an integer, Simulink displays N/S (not supported) for the parameter's value. If the parameter name is invalid, Simulink displays ??? as the parameter value.
The State Properties dialog box allows you to specify code generation options for certain blocks with discrete states. See Block State Storage and Interfacing in Real-Time Workshop® User's Guide for more information.
![]() | Editing Blocks | Changing a Block's Appearance | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |