Main Content

Create a Mask to Share Parameters with Simulink

Creating masks for Stateflow® charts, state transition tables, and truth tables simplifies how you use and share blocks in a Simulink® model. The mask encapsulates the block by hiding the underlying logic and creates a user interface for the block. You can customize the block by:

  • Changing the appearance with meaningful icons and ports.

  • Creating a user interface for parameters.

  • Adding customized documentation.

You decide which parameters to change through the mask user interface. You can provide meaningful descriptions of these parameters. For example, in the model sf_car, the shift_logic chart has a mask through which you can adjust the parameter TWAIT. To open the model, enter:


To open the Mask Parameters dialog box, double-click the Stateflow chart. This dialog box contains a parameter description "Delay before gear change (tick)" and a box to edit the value. This value is tied to the parameter TWAIT inside the mask. When you edit the value in this box, Stateflow assigns the new value to TWAIT during simulation.

Mask Parameters dialog box for shift_logic chart.

You can create other types of user interfaces for the mask parameters, such as check boxes, context menus, and option buttons.

You can create masks on Stateflow blocks accessible from the Simulink library: charts, state transition tables, and truth tables. You cannot mask atomic subcharts, states, or any other objects within a chart.

For more information, see Author Block Masks (Simulink).

Create a Mask for a Stateflow Chart

To create a mask for the Stateflow chart in the model old_sf_car:

  1. Open the model.


    This image shows the example model from running the command above.

  2. In the Simulink Editor, select the chart shift_logic.

  3. Open the Mask Editor. In the State Chart tab, click Create Mask.

Add an Icon to the Mask

To customize the appearance of the block icon, use drawing commands or load an image. For more information, see Mask Display and Initialization Commands (Simulink).

  1. In the Mask Editor, select the Icon tab.

  2. In the edit box, enter:

  3. Click Save Mask.

Add Parameters to the Mask

When you create a mask for a Stateflow block, you can define a custom interface for the block parameters. You provide access to the block parameters by defining corresponding parameters with the same name in the Mask Editor. A user interface to these parameters is then provided through a Mask Parameters dialog box. The mask parameters appear as editable fields in the Mask Parameters dialog box. Stateflow applies these values to the corresponding block parameters during simulation.

For example, the chart shift_logic has a parameter TWAIT. To add TWAIT as a parameter to the mask:

  1. In the Mask Editor, select the Parameters & Dialog tab.

  2. In the Controls pane, under Parameter, click the Edit icon.

  3. Under Prompt, enter the prompt for the new mask parameter in the Mask Parameters dialog box:

    Delay before gear change(tick)
  4. Under Name, enter the name of the parameter in the mask:

  5. Click Save Mask.

View the New Mask

After creating a mask, the new icon for the shift_logic chart appears in the Simulink canvas. If you double-click the icon, the Mask Parameters dialog box opens. This dialog box has the prompt for the parameter TWAIT. The value in the edit box is assigned to the parameter TWAIT during simulation.

Simulink model that contains a Stateflow chart with a mask.

Look Under the Mask

You can view and edit the contents of a masked block by clicking the Look inside mask badge on the chart. The badge is a downward facing arrow in the lower-left corner of the chart. Alternatively, in the State Chart tab, click Look Under Mask. Looking under a mask does not unmask the block.

Edit the Mask

To edit a mask, in the State Chart tab, click Edit Mask. In the Mask Editor, you can modify the mask icon, change the parameters, or add documentation. To remove the mask, click Unmask in the lower corner of the Mask Editor. After you change a mask, click Apply to save the changes.

Related Topics