Dynamic Mask Dialog Box
You can create dialogs for masked blocks whose appearance changes in response to user input. Features of masked dialog boxes that can change in this way include:
Visibility of parameter controls — Changing a parameter can cause the control for another parameter to appear or disappear. The dialog expands or shrinks when a control appears or disappears, respectively.
Enabled state of parameter controls — Changing a parameter can cause the control for another parameter to be enabled or disabled for input. A disabled control is grayed to indicate visually that it is disabled.
Parameter values — Changing a mask dialog box parameter can cause related mask dialog box parameters to be set to appropriate values.
Note
Mask parameter addition, deletion, or modification is restricted from mask callback.
Creating a dynamic masked dialog box entails using the Mask Editor with the
set_param
command. Specifically, you use the Mask Editor to define
parameters of the dialog box, both static and dynamic. For each dynamic parameter, you enter a
callback function that defines how the dialog box responds to changes to that parameter (see
Execute Callback Code). The callback function can in turn use the
set_param
command to set mask parameters that affect the appearance and
settings of other controls on the dialog box (see Create Dynamic Mask Dialog Box). Finally, you save the model or library
containing the masked subsystem to complete the creation of the dynamic masked dialog
box.
Show Parameter
The selected parameter appears on the mask dialog box only if this option is checked (the default).
Enable Parameter
Clearing this option grays the prompt of the selected parameter and disables the edit control of the prompt.
Create Dynamic Mask Dialog Box
This example shows how to create a mask dialog blocks whose appearance changes in response to your input.
You can set two parameters using this mask dialog box. The first parameter is a popup
menu through which you select one of three gain values: 2
,
5
, or User-defined
. Depending on the value that you
select in this popup menu, an edit field for specifying the gain appears or
disappears.
Select a subsystem and on the Subsystem Block tab, in the Mask group, click Create Mask.
Select the Parameters & Dialog pane on the Mask Editor.
Drag and drop a Popup parameter and select it in the Dialog box pane.
In the Prompt field, enter
Gain
.In the Name field, enter
gainpopup
.In the Property editor pane, clear Evaluate so that Simulink® uses the literal values you specify for the popup.
In the Type options field, click the Edit button to enter these three values in the Popup Options dialog box:
2 5 User-defined
Enter this code in the Dialog callback field:
% Get the mask parameter values. This is a cell % array of character vectors. maskStr = get_param(gcb,'gainpopup'); % The pop-up menu is the first mask parameter. % Check the value selected in the pop-up if strcmp(maskStr(1),'U'), % Set the visibility of both parameters on when % User-defined is selected in the pop-up. set_param(gcb,'MaskVisibilities',{'on';'on'}), else % Turn off the visibility of the Value field % when User-defined is not selected. set_param(gcb,'MaskVisibilities',{'on';'off'}), % Set the character vector in the Values field equal to the % character vector selected in the Gain pop-up menu. %maskStr{2}=maskStr{1}; set_param(gcb,'editvalue',maskStr); end
Drag and drop an Edit parameter and select it in the Dialog box pane.
In the Prompt field, enter
Value
.In the Name field, enter
editvalue
.In the Property editor pane, clear Visible so that Simulink turns off the visibility of this property by default.
Click Apply.
To open the mask dialog box, double-click the masked subsystem.
If you select
2
or5
as the Gain, Simulink hides the Value. If you selectUser-defined
as the Gain the Value is visible.
Set Up Nested Masked Block Parameters
Unresolved symbol errors occur if child level masked subsystems reference symbols defined by parent level masked subsystem and you try to set parameters of blocks at child level masked subsystems.
For example, a masked subsystem A contains masked subsystem B, which contains Gain block C, whose Gain parameter references a variable defined by B. If subsystem A's initialization code contains this command:
set_param([gcb '/B/C'], 'SampleTime', '-1');
Simulating or updating a model containing A causes an unresolved symbol error.