Mask Callback Code
Add Mask Code
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 pane|
|Callback code for mask parameters||Parameters & Dialog pane|
Execute Drawing Command
Place MATLAB code for drawing mask icons in the Icon Drawing Commands section of the Icon 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.
Placing MATLAB code for drawing mask icons in the Initialization section affects model performance. This behavior is because Simulink redraws the icon each time the masked block is evaluated in the model.
Execute Initialization Command
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, such as
MaskInitialization, 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.
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.
The non-tunable parameters of a masked block are not evaluated if the model is already compiled (initialized).
Execute Callback Code
Mask parameter callback codes are executed in a temporary workspace and not in the base workspace. If you need a variable created in the callback to be available later(not during callback processing), you must explicitly assign those variables to the base workspace.
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.
You modify the parameter value by using the
set_paramcommand, the callback commands execute.
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 Code Pane.
You hover over a masked block to see the tool tip for the block, when the tool tip contains parameter names and values.
Callback commands do not execute if the mask dialog box is open when the block tool tip appears.
You update a diagram by pressing Ctrl+D or by clicking Update Model on the Modeling tab in the Simulink Editor.
If you close a mask dialog box without saving the changes, the Callback command for parameters is executed sequentially.
Buttons on mask dialog box are unavailable when the callback code associated with the button is being executed.
For related Simulink example models, see: