Documentation

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.

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

Execute Drawing Command

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.

Execute Initialization Command

Initialization commands for all masked blocks in a model run when you:

  • Update the diagram

  • Start simulation

  • Start code generation

  • Apply mask changes

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

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

Execute Callback Code

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.

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

See Also

|

Was this topic helpful?