Draw Mask Icon

This example shows how to use drawing commands to create a mask icon. You can create icons that update when you change the mask parameters, thereby reflecting the purpose of the block.

Draw static icon

A static mask icon remains unchanged, independent of the value of the mask parameters.

  1. Right-click the masked block that requires the icon and select Mask > Edit Mask.

    The Mask Editor appears.

  2. In the Icons & Ports tab, enter the following command in the Icon Drawing commands pane:

    % Use specified image as mask icon
    image('engine.jpg')

    The image file must be on the MATLAB® path. You can use images in .svg format as block mask image.

    For more examples of drawing command syntax, explore the Command drop-down list in the Examples of drawing commands pane.

    Images in formats: .cur, .hdf4, .ico, .pcx, .ras, .xwd cannot be used as block mask images. However, you can use images in these formats if you wrap the filename in the imread() function and use the RGB triplet. Using the imread() function is not efficient, however it is still supported for backward compatibility.

Draw dynamic icon

A dynamic icon changes with the values of the mask parameters. Use it to represent the purpose of the masked block.

  1. Right-click the masked block that requires the icon and select Mask > Edit Mask.

    The Mask Editor appears.

  2. In the Icons & Ports tab, enter the following command in the Icon Drawing commands pane:

    pos = get_param(gcb, 'Position');
    width = pos(3) - pos(1);
    x = [0, width];
    y = m*x + b;
    plot(x,y)
  3. Under Options, set Icon Units to Pixels.

    The drop-down lists under Options allow you to specify icon frame visibility, icon transparency, drawing context, icon rotation, and port rotation.

  4. Click Apply. If Simulink® cannot evaluate all commands in the Icon Drawing commands pane to generate an icon, three question marks (? ? ?) appear on the mask. See model masking_examplemasking_example to view the icon generated.

Additional examples

See model slexMaskDisplayAndInitializationExampleslexMaskDisplayAndInitializationExample for more examples of icon drawing commands. This model shows how to draw:

  • a static mask

  • a dynamic shape mask

  • a dynamic text mask

  • an image mask

Was this topic helpful?