Set Block Properties

For each block in a model, you can set general block properties, such as:

  • A description of the block

  • The block's order of execution

  • A block annotation

  • Block callback functions

Block Properties Dialog Box

To set these block properties, open the Block Properties dialog box.

  1. In the Simulink® Editor, select the block.

  2. Select Diagram > Properties.

The Block Properties dialog box opens, with the General tab open. For example:

To open the Block Parameters dialog box for the block, in the General tab of the Block Properties dialog box, click the Open Block link. Use the Block Parameters dialog box to specify values for attributes that are specific each block.

    Note   Some blocks, such as Scope blocks, do not have a Block Parameters dialog box.

    Using the Block Properties dialog box Open Block link to open the Block Parameters dialog box works for all blocks that have parameter dialog boxes, except for Subsystem and Model blocks. Use the Simulink Editor Diagram menu or the block context menu to open the Block Parameters dialog box for Subsystem and Model blocks.

General Block Properties

Description

Enter a brief description of the purpose of the block or any other descriptive information.

Priority

Specify the execution priority of this block relative to other blocks in the model. For more information, see Assign Block Priorities.

Tag

You can use a tag to create your own block-specific label for a block. Specify text that Simulink assigns to the block's Tag parameter and saves with the block in the model.

Block Annotation Properties

Use the Block Annotation tab 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, Simulink 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 Simulink Editor model 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 Common Block Properties and Block-Specific Parameters). 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 Create Block Annotations Programmatically.

Block Callbacks

Use the Callbacks tab to specify implementations for a block's callbacks (see Callbacks for Customized Model Behavior).

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.

Modify Behavior for Opening a Block

You can use the OpenFcn callback to automatically execute MATLAB scripts when the you double-click a block. MATLAB scripts can perform many different tasks, such as defining variables for a block, making a call to MATLAB that brings up a plot of simulated data, or generating a GUI.

The OpenFcn overrides the normal behavior which occurs when opening a block (its parameter dialog box is displayed or a subsystem is opened).

To create block callbacks interactively, open the block's Block Properties dialog box and use the Callbacks tab to edit callbacks (see Callbacks for Customized Model Behavior).

To create the OpenFcn callback programmatically, click the block to which you want to add this property, then enter the following at the MATLAB command prompt:

set_param(gcb,'OpenFcn','expression')

where expression is a valid MATLAB command or a MATLAB script that exists in your MATLAB search path.

The following example shows how to set up the callback to execute a MATLAB script called myfunction.m when double clicking a subsystem called mysubsystem.

set_param('mymodelname/mysubsystem','OpenFcn','myfunction')

Create Block Annotations Programmatically

You can use a block's AttributesFormatString parameter to display selected block parameters beneath the block as an "attributes format string," which is a string that specifies values of the block's attributes (parameters). Common Block Properties and Block-Specific Parameters describe 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, enter the following at the MATLAB command prompt:

The Gain block displays the following block annotation:

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.

Was this topic helpful?