You can use MATLAB® code to initialize a mask and to draw mask icons. Since the location of code affects model performance, add your code to reflect the functionality you need.
|Purpose||Add 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 when:
Block is rendered first on the Mask Editor canvas.
Mask parameters and values that depend on drawing commands change.
Block appearance is altered due to rotation or other changes.
Note: Placing MATLAB code for drawing mask icons in the Initialization pane affects model performance. This behavior is because Simulink redraws the icon each time the masked block is evaluated in the model.
Initialization commands for all masked blocks in a model run when you:
Update the diagram
Start code generation
Apply mask changes
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.
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 during model load.
The masked subsystem belongs to a library and has the Allow library block to modify its contents parameter enabled.
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.
Note: The non-tunable parameters of a masked block are not evaluated if the model is already complied (initialized).
Simulink executes the callback commands when:
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 location. For example, you press the Tab key or click into another field in the dialog box after changing the parameter value.
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. For
more information, see Initialization Pane.
You hover over a masked block to see the tool tip for the block, when the tool tip contains parameter names and values.
Note: Callback commands do not execute if the mask dialog box is open when the block tool tip appears.
You update a diagram (for example, by pressing Ctrl+D or by selecting Simulation > Update diagram in the Simulink Editor).
If you close a mask dialog box without saving the changes, the Callback command for parameters is executed sequentially.
Note: Buttons on mask dialog box are unavailable when the callback code associated with the button is being executed.
For related Simulink example models, see: