Create Dynamic Mask Dialog Boxes

About Dynamic Masked Dialog Boxes

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 Setting Masked Block Dialog Box Parameters). 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.

Setting Masked Block Dialog Box Parameters

The following example creates a mask dialog box with two parameters. The first parameter is a pop-up menu that selects one of three gain values: 2, 5, or User-defined. The selection in this popup menu determines the visibility of an edit field for specifying the gain.

  1. Mask a subsystem: Right-click the block and select 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, uncheck 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,'MaskValues');
    % The pop-up menu is the first mask parameter.
    %   Check the value selected in the pop-up 
    if strcmp(maskStr{1}(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. Add a second parameter.

    • Enter Value: in the Prompt field.

    • In the Property editor pane, enter val in the Value field.

    • Uncheck Visible property in the Properties pane. This step turns the visibility of this parameter off, by default.

  6. Select Apply on the Mask Editor.

Double-clicking on the new masked subsystem opens the mask dialog box. Selecting 2 or 5 for the Gain parameter hides the Value parameter, while selecting User-defined makes the Value parameter visible. Note that any blocks in the masked subsystem that need the gain value should reference the mask variable val as the set_param in the else code assures that val contains the current value of the gain when 2 or 5 is selected in the popup.

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.

Was this topic helpful?