|On this page…|
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||MaskInitialization parameter|
|Draw mask icon||Icon & Ports pane||MaskDisplay parameter|
|Callback code for mask parameters||Parameters & Dialog pane||MaskCallbacks parameter|
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.
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.
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, such as MaskDisplay and MaskInitialization, 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 drawing depends 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 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).
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.
Update a diagram (for example, by pressing Ctrl+D or by selecting Simulation > Update diagram in the Simulink Editor).