Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Seth on Simulink

August 5th, 2008

Advanced Masking Concepts

Masking does more than just put a professional interface on your algorithm.  Simulink blocksets provide elaborate graphical user interfaces (GUIs) to control the behavior of blocks.  The block dialog can dynamically enable and disable its GUI elements.  Blocks can sprout additional ports in order to accept parameters as input signals.  The algorithm can rewire itself based on the setting in the dialog.  Did you ever ask yourself, “how can I do that?”

This is the first in a series of posts that will introduce these advanced masking concepts.  I have created an example that has:

  • A block dialog that enables and disables parameters based on user settings
  • The option to add and delete ports to match dialog settings

This example builds on top of the basic concepts introduced in my recent post on masking.  That post covered how to make a mask icon, and provide a mask dialog to control the parameters used in an algorithm.

Two saturation blocks

The example I have created combines the dynamic saturation block from a recent post on libraries and the fixed saturation block in my recent post on masking.  The algorithms for these two blocks differ slightly.  The dynamic saturation block uses inports to provide the limits, and the fixed saturation uses constant blocks to provide the same signals.

Dynamic limits and fixed limits saturation systems

The Fixed Saturation block has a mask that sets the values of the uplim and lowlim variables in the mask workspace.

Fixed saturation limit mask dialog

A combined saturation block interface

To combine these blocks, I present the user with a simple interface that allows them to control the source of their upper and lower saturation limits.  The value can be internal or external. 

Mask dialog for the saturation block, internal source for limits

When internal limits are used, the value comes from the Upper Limit and Lower Limit fields.  When using external limits, those fields are disabled, and inports provide the limit signals.

Mask dialog for the saturation block, external source for limits

How does this combined block work?

Here is a test model that exercises some of the different modes of this saturation block.  The three saturation blocks in this model are actually three instances of the same library block.

Saturation block test model

The top block uses the fixed limits.  The middle block uses an external source for the upper limit and a fixed value for the lower limit.  The bottom block uses external sources for both the upper and lower limit.

Saturatino block test model scopes

How does the same block behave in these three different ways?  To see how, you can look under the masks of these blocks and see the blocks involved in the algorithm.

Algorithms for three instances of the saturation block, fixed limits, dynamic upper and fixed lower, dynamic upper and lower

All three instances of the subsystems get their upper limit from a block named system/up, and their lower limit from a block named system/lo.  In the case where the limits are fixed, the block is a constant block.  In the case where the limit is dynamic (external source), the block is an inport.  To achieve this, the block runs some M-code that replaces the Constant block with an Inport when the source is external and replaces the Inport with a Constant block when the source is internal.

In future posts we will examine:

  • Mask dialog callbacks
  • Mask initialization and self modifiable library blocks
  • Best practices for masking

Now it’s your turn

Have you implemented masks using these concepts?  Share your experience here.

One Response to “Advanced Masking Concepts”

  1. Bob replied on :

    I’ve done a few more advanced blocks like this. While a bit more complex than regular blocks, I’ve found them much easier to debug than doing the equivalent in S-Functions.

    Although, I tend to hide unused parameters rather than just grey them out.

Leave a Reply


Seth Popinchalk is an Application Engineer for The MathWorks. He writes here about Simulink and other MathWorks tools used in Model-Based Design.
  • Amin: Hi Seth! Is it necessary to rest the position integral in the bouncing ball demo? I get same result without...
  • parth damani: This was very helpful. I want one help about if you have any idea. I want to generate .mdl file from .m...
  • Seth: @ John Reily - The string entered into your mask will be evaluated in the parent workspace, (it could come from...
  • Seth: @Quan - Thanks for the compliment! @Jim - The two methods can be combined. If you have large structural changes...
  • Jim: I have used configurable subsystems in my library to provide a similar capability - one block provides multiple...
  • John Reilly: Seth: Thanks for a great series. As I am in the process of building a set of Simulink blocks, these were...
  • RAMYA: sir, am pursuing my masters in communication engineering. i am finding some difficult in implementing a block...
  • Quan: Hi Seth, Great graphics you got here. I especially like the first one, cool animated picture! I”m not a...
  • ChinKeat Low: Hi. I’m a new user of Matlab & Simulink. I would like to know more on building and simulating...
  • Alex: Is it possible to dynamically change the MaskStyle, i.e. change the text entries of a popup parameter? For...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics