Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Creating Dynamic Mask Dialog Boxes

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 unresolvable 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 unresolvable symbol error.

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

Creating a dynamic masked dialog entails using the Mask Editor in combination with the set_param command. Specifically, you use the Mask Editor to define the dialog's parameters, both static and dynamic. For each dynamic parameter, you enter a callback function that defines the dialog's response to changes to that parameter (see ). The callback function can in turn use the set_param command to set mask dialog parameters that affect the appearance and settings of other controls on the dialog (see ). Finally, you save the model or library containing the masked subsystem to complete the creation of the dynamic masked dialog.

Show parameter

The selected parameter appears on the Mask Parameters dialog box only if this option is checked (the default).

Enable parameter

Clearing this option grays the selected parameter's prompt and disables its edit control. This means that the user cannot set the value of the parameter.

Setting Masked Block Dialog Parameters

The following example creates a mask dialog 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 pop-up menu determines the visibility of an edit field used to specify the user-defined gain.

  1. Mask a subsystem as described in steps one and two in Masking a Subsystem.

  2. Select the Parameters pane on the Mask Editor.

  3. Add a parameter.

    • Enter Gain: in the Prompt field

    • Enter gain in the Variable field

    • Select popup in the Type field

  4. Enter the following three values in the Popups (one per line) field:

    2
    5
    User-defined
  5. 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.
    
        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 string in the Values field equal to the
        % string selected in the Gain pop-up menu.
    
        maskStr{2}=maskStr{1};
        set_param(gcb,'MaskValues',maskStr);
    end
  6. Add a second parameter.

    • Enter Value: in the Prompt field

    • Enter val in the Variable field

    • Uncheck Show parameter in the Options for selected parameter group. This turns the visibility of this parameter off, by default.

  7. Select Apply on the Mask Editor. The Mask Editor now looks like this when the gain parameter is selected and comments are removed from the mask callback code:

Double-clicking on the new masked subsystem opens the Mask Parameters 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS