Greg's pick this week is Dynamic Mask Field Changing From Selected Pulldown Menu by David Manegold.
Ever wanted to change how your Simulink block mask appears depending on certain parameter conditions of the mask? David has a nice example.
I selected this submission because it demonstrates an advanced Simulink development technique in a straight-forward manner.
Masks have the ability to change what parameters are available depending on which parameters have been selected. In this example, if the value of the "Selector" parameters is "A" then the set of parameters associated with "A" appears in the mask. But if you select "C" instead, then a new set of parameters is displayed. Also option "C" has a subset of parameters that can also change depending on what you choose for "C alt field type 3".
The mask is a dialog box that appears when you double-click on a block in Simulink. It provides a means to enter parameters for a Simulink block or subsystem to affect its functionality. This means you can have two instances of a block or subsystem in the same model that exhibit different behavior depending on the parameter values entered in the mask. You can create your own masks for subsystems or blocks by right-clicking on the block and select
Mask -> Create mask...
For more information on creating masks see Create Mask Documentation.
David leverages two capabilities to enable this behavior in a block mask.
- Mask parameter callback function
- The MaskVisibilities property of the block
In the mask editor, if you select a parameter to edit, you can populate the "Dialog callback" field to execute MATLAB functions that get executed when the parameter is changed in the block mask.
Within the callback function ChangeMaskFields, David changes the visibility of specific parameters based on the value of the "Selector" parameter. He defaults the parameter visibilities to "off":
except for the first parameter (which is the Selector parameter):
Then he enables specific parameters based on the value of the "Selector" parameter:
If you would like to leave any comments regarding this post, please click here.
Get the MATLAB code
Published with MATLAB® R2013a
Comments are closed.
1 CommentsOldest to Newest
Good job Dave! Nice and clean implementation of the callback!