How to Create Masks in Simulink, Part 1: Introduction to Simulink Masking
From the series: How to Create Masks in Simulink
Watch an overview about Simulink® masks. Masks are a great way to add icons and a custom interface for your Simulink blocks and subsystems. Masks help you manage complexity in your models, control access to underlying block parameters, provide custom documentation for your block, and initialize block parameters using custom MATLAB® code.
Published: 18 Apr 2023
Masks are a great way to add icons and build a custom interface for your Simulink blocks. This can help you manage complexity in your models as well as control access to underlying block parameters, provide custom documentation for your block, and initialize block parameters using custom MATLAB code. Let's look at an example of a masked block in Simulink.
This model contains a subsystem block called AC System that represents an air conditioning system. Double clicking this block opens the masked dialog box, which can be used to adjust various parameters. These controls allow the user to pass information to the mask workspace and the underlying subsystem, all from a singular dialog box. This can be used to set parameter values for the individual blocks in the subsystem as well.
The various UI components can be easily assembled to accommodate different parameter types and descriptions. Masks can also customize the block icon, allowing you to display meaningful information directly on the block.
You can access the Mask Editor using the tool strip or by right clicking the block you would like to mask. This editor has several tabbed panes, each of which allows you to customize different features of the mask. The Parameters & Dialog pane enables you to design the mask dialog box. The left controls palette includes various controls, containers, and other UI components. Containers such as group boxes, tabs, and collapsible panels help to organize these components within the dialog box.
The Property Editor on the right allows you to specify properties of these components. The components highlighted in blue correspond to parameters identified by the name value. You can also use the Parameters & Dialog pane to promote parameters from the underlying block. Use the Promote One-to-One and Promote Many-to-One controls to set block parameters within the mask workspace.
You can also pass parameters to the underlying blocks, either by referencing the block parameters using variable names or by using mask initialization code in the Code pane. Parameter values set in the mask workspace take priority over those set in the model and base workspaces. Additionally, if you would like to include custom documentation for your block, you can also do this from this pane using the Documentation option in the tool strip.
The Code pane provides an editor for your block initialization code and any callback functions you have specified for controls. Using this pane, you can create and edit code within the Mask Editor or access a separate MATLAB file containing your code. The mask parameter constraints help you to validate parameters without the need for additional validation code. You can specify constraints for single parameters, across multiple parameters, and for block input and output ports.
Finally, the Icon tab allows you to customize the appearance of a masked block. You can do this by writing code using the various drawing commands located in the left palette or graphically using the various tools in the Graphical icon editor. You can also define additional functionality, such as text parameterization and conditional visibility from this tab. These are just some of the many things you can do with masks in Simulink.