Dynamic Mask Dialog Box

About Dynamic Masked 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.

Creating a dynamic masked dialog box entails using the Mask Editor in combination 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 Callback Code Execution). 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.

To view related example, see Create dynamic mask dialog boxes.

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. Mask a subsystem by right-clicking the block and selecting Mask > 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.

    • 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 the following three values in the Popup Options dialog box:


  4. Enter the following code in the Dialog callback field:

    % Get the mask parameter values. This is a cell
    %   array of strings.
    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 string in the Values field equal to the
        % string selected in the Gain pop-up menu.

  5. 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.

  6. Click Apply.

  7. Double-click the masked subsystem to open the mask dialog box.

    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.

Setting Nested Masked Block Parameters

Avoid using set_param commands to set parameters of blocks residing in masked subsystems that reside in the masked subsystem being initialized. Trying to set parameters of blocks in lower-level masked subsystems can trigger unresolved symbol errors if lower-level masked subsystems reference symbols defined by higher-level masked subsystems. Suppose, for example, a masked subsystem A contains masked subsystem B, which contains Gain block C, whose Gain parameter references a variable defined by B. Suppose also that subsystem A's initialization code contains the command

set_param([gcb '/B/C'], 'SampleTime', '-1');

Simulating or updating a model containing A causes an unresolved symbol error.

See Also


Was this topic helpful?