Today I want to introduce a fundamental Simulink concept: masking a block.  Masking provides you with a way to put an interface on an algorithm.  This can centralize the system parameters for easier viewing, or hide the complexity from unintentional tampering by other users.  Masking can also be used to dress up your model for more inviting or professional looking presentations.  Let me show you how by masking a subsystem that I made.

The subsystem holds the algorithm

In my example, I am masking a subsystem that contains a fixed limit saturation algorithm:

I will come back to this in my examples below.

Simulink models provide an executable specification.  The model allows you to share a picture of the system schematics that can be understood by everyone on the team, especially your boss or customer.  The best way to do this is to make the components in your diagram really obvious.  A great example of this is the f14_digital demo model.  This model uses images for the icon on three root level subsystems.

You can grab a picture of the stuff you are modeling and put it on the corresponding subsystems.  To do this, use the Edit > Mask Subsystem... menu when the block is selected.  This is also available from the right click menu on the block.  This opens the mask editor and brings up the icon tab for the block.

For my Saturation subsystem I have used the basic plot command to put an icon on the block.  I set the Units to normalized, which provide x and y range from zero to one for the canvas.

The allowed drawing commands are a subset of MATLAB graphics.  There are examples at the bottom of the mask editor.  The image command can be combined with IMREAD to load an image from your MATLAB path.  For example, the following drawing command adds a Boeing 747 icon to your block

image(imread('b747.jpg'))

Adding an icon to your system doesn’t change the behavior.  When you double click on the block, you will still open the system it contains.

A mask can also provide a simplified interface to the blocks underneath.  As a trainer, I used to introduce this concept as a method for preventing unintended tampering with the contents of your system.  The parameters tab of the Mask Editor is where you set the parameters for the system.

The Prompt is the string you want to display before the box where the user enters the value.  The Variable holds the value entered in the mask.  Adding dialog parameters creates a local workspace for the blocks under the mask.  In my fixed saturation example, the up and lo constant blocks will now use the variables from the mask as their value, instead of hard coding the constant in those blocks.

Add some details to the documentation tab to complete the mask dialog.

Mask type is used to specify a title for the dialog.  Mask description shows up right below that and provides a place for some quick reference documentation.  The Mask help field can be a long description that will be displayed as HTML when the user pushes the Help button.  HTTP links are also acceptable.  For a full list of the Mask help alternatives click here.  Double clicking on the icon of the Saturation block displays the finished dialog:

As you make edits in the Mask Editor you will notice that your parameter values in this dialog are set to 0.  Before you finish with your mask, make sure to set the parameter values for your system in the dialog.

How do I get back to the system?

Now that the block has a mask, double clicking on the icon opens the mask dialog.  The way you know you are looking at a mask dialog is the label following the system name: Saturation (mask).  To see the algorithm beneath the mask, right click on the block and select Look Under Mask.  This will bring you back to the contents of the system.