Main Content

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.


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.

  1. Select a subsystem and on the Subsystem Block tab, in the Mask group, click Create Mask.

  2. Select the Parameters & Dialog pane on the Mask Editor.

  3. Drag and drop a Popup parameter and select it in the Dialog box pane.

    1. In the Prompt field, enter Gain.

    2. In the Name field, enter gainpopup.

    3. In the Property editor pane, clear Evaluate so that Simulink® uses the literal values you specify for the popup.

    4. In the Type options field, click the Edit button to enter these three values in the Popup Options dialog box:


  4. 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.
        % Turn off the visibility of the Value field
        %   when User-defined is not selected.
        % Set the character vector in the Values field equal to the
        % character vector selected in the Gain pop-up menu.

  5. Drag and drop an Edit parameter and select it in the Dialog box pane.

    1. In the Prompt field, enter Value.

    2. In the Name field, enter editvalue.

    3. In the Property editor pane, clear Visible so that Simulink turns off the visibility of this property by default.

  6. Click Apply.

  7. To open the mask dialog box, double-click the masked subsystem.

    If you select 2 or 5 as the Gain, Simulink hides the Value. If you select User-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.

Related Topics