You can use MATLAB® code to initialize a mask as well as to draw mask icons. Since the location of code affects model performance, place your code to reflect the functionality you need.
|Purpose||Placement in Mask Editor||Programmatic Specification|
|Initialize the mask||Initialization pane|
|Draw mask icon||Icon & Ports pane|
|Callback code for mask parameters||Parameters & Dialog pane|
Place MATLAB code for drawing mask icons in the Icon Drawing Commands section of the Icon & Ports pane. Simulink® executes these commands sequentially to redraw the mask icon in the following cases:
The drawing commands are dependent on mask parameters and the values of these mask parameters change.
The block appearance is altered due to rotation or other changes.
Note: If you place MATLAB code for drawing mask icons in the Initialization pane, model performance is affected, because Simulink redraws the icon each time the masked block is evaluated in the model.
When you open a model, Simulink locates visible masked blocks that reside at the top level of the model or in an open subsystem. Simulink only executes the initialization commands for these visible masked blocks if they meet either of the following conditions:
The masked block has icon drawing commands.
Note: Simulink does not initialize masked blocks that do not have icon drawing commands, even if they have initialization commands.
The masked subsystem belongs to a library and has the Allow library block to modify its contents parameter enabled.
Simulink initializes masked blocks that are not initially visible when you open the model that contains these blocks.
When you load a model into memory without displaying it graphically,
no initialization commands initially run for any masked blocks. See Load 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 code generation
Initialization commands for an individual masked block run when you:
Change any of the parameters that define the mask,
using the Mask Editor or
Rotate or flip the masked block, if the icon depends on initialization commands.
Cause the icon to be drawn or redrawn, and the icon drawing depends on initialization code.
Change the value of a mask parameter by using the
block dialog box or
Copy the masked block within the same model or between different models.
Simulink executes the callback commands in the following cases:
You open the mask dialog box. Callback commands execute sequentially, starting with the top mask dialog box.
You modify a parameter value in the mask 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).
When you modify the parameter value by using the
You modify the parameter value, either in the mask
dialog box or using
set_param, and then apply the
change by clicking Apply or OK.
Mask initialization commands execute after callback commands (See Initialization Pane).
You hover over a 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.
Note: Callback commands do not execute if the mask dialog box is open when the block data tip appears.
Update a diagram (for example, by pressing Ctrl+D or by selecting Simulation > Update diagram in the Simulink Editor).