| Contents | Index |
| On this page… |
|---|
You can specify MATLAB code for masked blocks in both the mask initialization code and in the block icon drawing code. The location of code affects model performance. In general, partition your code to reflect the functionality you need.
Keep initialization code together in the Initialization pane (or in the MaskInitialization parameter).
Keep icon drawing code, including variable definitions, together in the Icon & Ports pane (or in the MaskDisplayMaskDisplay parameter).
Keep Mask Parameters dialog box callback code in the Parameters pane (or in the MaskCallbacks parameter).
Simulink executes the drawing commands in the Drawing Commands pane in the sequence in which the commands appear whenever the block has to be drawn or redrawn.
If the drawing commands are dependent on the mask workspace and the mask workspace changes (that is, mask parameter values change), then the drawing commands execute.
Rotation and other changes that affect the appearance of the block cause the icon to be redrawn.
When you open a model, initialization commands execute for masked blocks that are visible because they reside at the top level of the model or in an open subsystem and that meet either of the following conditions:
The masked block has icon drawing commands.
The masked subsystem is from a library and has the Allow library block to modify its contents parameter enabled.
A simple masked block that has initialization commands but no icon drawing commands does not execute the initialization commands when you open the model.
Initialization commands for masked blocks that are not initially visible execute when you open the subsystem or model that contains the blocks.
When you load a model into memory without displaying the model graphically, no initialization commands initially run for any masked blocks. See Loading a Model and load_system for information about loading a model without displaying it.
Initialization commands for all masked blocks in a model that have drawing commands run when you:
Update the diagram
Start simulation
Start code generation
Initialization commands for an individual masked block run when you:
Change any of the parameters that define the mask, such as MaskDisplay and MaskInitialization, by using the Mask Editor or set_param
Rotate or flip the masked block, if the icon depends on initialization commands
Cause the icon to be drawn or redrawn, and the icon display commands depend on initialization code.
Change the value of a mask parameter by using the block dialog box or set_param
Copy the masked block within the same model or between different models
Simulink executes the callback commands when you:
Open the Mask Parameters dialog box. Callback commands execute top down, starting with the top mask dialog box parameter.
Modify a parameter value in the Mask Parameters dialog box and then change the cursor's focus (that is, you press the Tab key or click into another field in the dialog box).
Modify the parameter value, either in the Mask Parameters dialog box or via a call to set_param, and then apply the change by clicking Apply or OK. Mask initialization commands execute after the callback commands. (See Initialization Pane.)
Hover over the masked block to see the data tip for the block, when the data tip contains parameter names and values. The callback executes again when the block data tip disappears.
Update a diagram (for example, by pressing Ctrl-D or by selecting the Edit > Update diagram menu item).
![]() | Creating Dynamic Masked Subsystems | Debugging Masks That Use MATLAB Code | ![]() |

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 |