Mask Code Execution

Mask Code Placement

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.

PurposePlacement in Mask EditorProgrammatic Specification
Initialize the maskInitialization paneMaskInitialization parameter
Draw mask iconIcon & Ports paneMaskDisplay parameter
Callback code for mask parametersParameters & Dialog paneMaskCallbacks parameter

Drawing Command Execution

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.

Initialization Command Execution

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 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, 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.

Callback Code Execution

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).

      Note:   When you modify the parameter value by using the set_param command, the callback commands do not 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 (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).

  • If you close a mask dialog box without saving the changes, the Callback command for parameters is sequentially executed.

To view related examples, see

More About

Was this topic helpful?