Main Content

Mask Display and Initialization Commands

Create icons for the masked blocks. You can either create static or dynamic icons. Static icons remain unchanged. Dynamic icons are created with the mask parameters, hence the icon changes with a change in the mask parameters. This example shows how to use drawing commands to create a mask icon.

Explore the Model

This model has four subsystem blocks which demonstrates drawing static and dynamic mask icons.

open_system("slexMaskDisplayAndInitializationExample");

Draw Static Icon

A static mask icon remains unchanged, independent of the value of the mask parameters. To create a static icon:

1. Right click the block Independent static Icon > Mask > Edit Mask.

2. Go to Icon pane, and use the patch command to draw color patch of specified shape on masked icon.

patch([0 5 10 15 20 15 10 5 0], [0 20 8 20 0 16 6 16 0], [0 0 1])

You can also select an image to display on the mask icon.

Note: If the icon drawing commands are dependent on the mask parameters then set the property Run Initialization.

Draw Dynamic Icon

Draw Dynamic Icon Depending on Mask Parameters

A dynamic icon changes with the values of the mask parameters. In this example, the shape of the icon changes between triangle or quadrilateral based on the mask popup parameter. Also, the color intensity of the shape can be changed based on the mask parameter.

To create a dynamic icon:

1. Right-click the block Icon Dependent on Parameters > Mask > Edit Mask.

2. Create a popup parameter graphic_opt, enter the Type options as Triangle and Quadrilateral.

3. Create an edit parameter colorIntensity to control the color intensity of the shape.

4. Use this code in the Icon pane.

Use get_param to obtain the text of the selected element

gr_opt = get_param(gcb, 'graphic_opt');
if strcmp(gr_opt,'Quadrilateral')
 % Here we can use the mask parameter 'colorIntensity'
 % directly because it is of type 'edit'
    patch([1 4 12 22], [3 23 32 10], [1 0 0]*colorIntensity);
elseif strcmp(gr_opt,'Triangle')
    patch([4 12 22], [23 32 10], [1 0 0]*colorIntensity);
end

Double-click the block Icon Dependent on Parameters to view the block parameters. Select the Shape as Quadrilateral and enter Color Intensity as .8. Click Ok to see the change in mask icon.

Draw Mask Icon Depending on Mask Workspace Variable

You can either use a mask parameter to directly control the mask icon or use a derived mask parameter to control the mask icon. In this example, the mask parameter is multiplied by four and the result is displayed in the mask icon.

1. Right-click the block Icon Dependent on Mask Workspace > Mask > Edit Mask.

2. Create an edit parameter gain_val_param and set the initial value to 2.

3. In the Code pane, use this code to multiply the initial value of the mask parameter by 4.

function initialization()
final_gain_val = gain_val_param * 4;
end

4. In the Icon pane, use this code to display the value on the mask icon.

disp(['Final Gain Value: ',num2str(final_gain_val)])

Double-click the block Icon Dependent on Mask Workspace to view the block parameters. Enter the value for the Gain Value parameter and click Ok to see the change in mask icon.

Note: If Simulink® cannot evaluate all commands in the Icon Drawing commands pane to generate an icon, three question marks (? ? ?) appear on the mask.

Related Topics