Working with Block Parameters

About Block Parameters

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

Mathematical Versus Configuration 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).

Setting Block Parameters

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:

Displaying a Block's Parameter Dialog Box

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.

Specifying Numeric 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.

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

Resolving 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 Resolving Symbols and Specifying Numeric Values with Symbols for more information.

Using 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. 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).

Determining 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).

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')

Checking Parameter Values

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:

Blocks That Perform Parameter Range Checking

The following blocks perform range checking for their parameters:

BlockParameters Checked

Constant

Constant value

Data Store Memory

Initial value

Gain

Gain

Interpolation Using Prelookup

Table data

Lookup Table

Table data

Lookup Table (2-D)

Table data

Lookup Table (n-D)

Table data

Relay

Output when on
Output when off

Repeating Sequence Interpolated

Vector of output values

Repeating Sequence Stair

Vector of output values

Saturation

Upper limit
Lower limit

Specifying Ranges for Parameters

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:

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

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))

Performing Parameter Range Checking

You can initiate parameter range checking in the following ways:

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

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

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:

Changing the Values of Block Parameters During Simulation

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.

Tuning a Block Parameter

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

Changing Source Block Parameters During Simulation

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.

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.

Inlining Parameters

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.

Specifying Some Parameters as Noninline

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.

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.

Block Properties 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:

General Pane

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.

Block Annotation Pane

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.

Callbacks Pane

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.

Creating Block Annotations Programmatically

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.

State Properties Dialog Box

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.

  


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