Main Content

Specify Block Properties

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

  • A description of the block

  • The block execution order

  • A block annotation

  • Block callback functions

To set block properties, use the Property Inspector. You can set properties in thePropertiesandInfotabs of the Property Inspector when the block is selected. Alternatively, you can use the Block Properties dialog box.

Set Block Annotation Properties

In the Property Inspector, use theBlock Annotationsection to display the values of selected block parameters in an annotation. The annotation appears below the block icon.

Enter the text of the annotation in the text box. You can use a block property token in the annotation. The value for the property replaces the token in the annotation in the model. To display a list of tokens that you can use in an annotation, type%in the text box. The parameters that are valid for the selected block appear. SeeCommon Block PropertiesandBlock-Specific Parameters.

Suppose that you specify the following annotation text and tokens for a Product block:

Multiplication = % Sample time = %

In the Simulink®Editor, the block displays this annotation:

You can also create block annotations programmatically. SeeCreate Block Annotations Programmatically.

Specify Block Callbacks

Use theCallbackssection to specify block callbacks. Callbacks are MATLAB®命令那t execute when a specific model action occurs, such as when you select or delete a block. For more information on callbacks, seeCallbacks for Customized Model Behavior.

  1. Select the block whose callback you want to set.

  2. InPropertiestab of the Property Inspector, in theCallbackssection, select the function that you want to assign the callback to. For example, selectOpenFcnto specify a behavior for double-clicking a block.

  3. In the text box, enter the command that you want to execute when that block function occurs.

    After you assign a callback to a function, the function displays an asterisk next to it in the list. The asterisks helps you to see the functions that have callbacks assigned to them.

    Note

    After you add anOpenFcncallback to a block, double-clicking the block does not open the block dialog box. Also, the block parameters do not appear in the Property Inspector when the block is selected. To set the block parameters, selectBlock Parametersfrom the block context menu.

Set a Block Callback Programmatically

This example shows how to use theOpenFcncallback to execute MATLAB scripts when you double-click a block. For example, in a MATLAB script you can define variables or open a plot of simulated data.

To create a callback programmatically, select the block to which you want to add this property. Then, at the MATLAB command prompt, enter a command in this form:

set_param(gcb,'OpenFcn','myfunction')
In this example,myfunctionrepresents a valid MATLAB command or a MATLAB script on your MATLAB search path.

Specify Block Execution Priority and Tag

In theAdvanced Propertiessection of the block properties, you can specify the block priority and identify the block by assigning a value to the标签property.

  • Priority— Specify the execution priority of the block relative to other blocks in the model.

  • 标签— Specify an identifier for the block. Specify text to assign to the block Tag parameter. Setting this property is useful for finding the block in the model by searching or programmatically usingfind_system. SeeExplore Model Hierarchy.

Use Block Description to Identify a Block

TheInfotab displays information about the block type. The block author provides this description.

You can also enter a description in theDescriptionbox to provide information about the block instance.

  • If you add a description, you can set up your model display so that the description appears in a tooltip when you hover over the block. To enable this tooltip, on theDebugtab, selectInformation Overlays>Description in Tooltip.

  • TheDescriptionproperty can help you to find a block by searching. SeeSimulink Editor.

Create Block Annotations Programmatically

You can use a blockAttributesFormatStringparameter to display specified block parameter values below the block.Common Block PropertiesandBlock-Specific Parametersdescribe the parameters that a block can have. Use the Simulinkset_paramfunction to set this parameter to the attributes format that you want.

The attributes format can be any text that has embedded parameter names. An embedded parameter name is a parameter name preceded by%<and followed by>, for example,%. Simulink displays the attributes format text below the block icon, replacing each parameter name with the corresponding value. You can use line-feed characters (\n) to display each parameter on a separate line. For example, select aGainblock and enter this command at the MATLAB command prompt:

set_param(gcb,“AttributesFormatString”,'pri=%\ngain=%')

The Gain block displays this block annotation:

If a parameter value is not text or an integer,N/S(for not supported) appears in place of the value. If the parameter name is not valid, Simulink displays???in place of the value.

Related Topics