Main Content

Dynamic Mask Dialog Box

You can create dialog boxes 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. 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. Finally, you save the model or library containing the masked subsystem to complete the creation of the dynamic masked dialog box.

Explore the Model

This example has two subsystem blocks Making a Parameter Invisible and Disabling a Parameter to change the visibility of the mask parameter and disable the mask parameter.

open_system("slexMaskDDGExample.slx");

Change the Visibility of a Mask Parameter

The subsystem block Making a Parameter Invisible is referenced to explain in this section. This example shows how to change the visibility of one mask parameter based on the value of another mask parameter. The value of Enable Bias is set by selecting or clearing the Enable Bias check box. It is used to change the visibility of the Bias Value parameter.

To change the visibility of the mask parameter:

1. Create two edit parameters Gain Value and Bias. Create a check box parameter Enable Bias.

2. Use this code in the Initialization section of the Code pane.

function initialization()
%In the Initialization command, the variable 'enableBias' corresponding to
the checkbox returns the following values:
unchecked = 0
checked = 1
% If the box is unchecked, we set the bias value to zero
if ~enableBias
  biasValue = 0;
end
% Otherwise, the value from the mask parameter is used
end

3. Use this code in the parameter callback section for enableBias.

function enableBias_callback()
% Control parameter visibility. Get the value of the Enable Bias checkbox
% unchecked = 'off'
% checked = 'on'
enab = get_param(gcb,'enableBias');
% Set the 'MaskVisibilities' property for each parameters
if strcmp(enab,'on')
  set_param(gcb,'MaskVisibilities',{'on','on','on'});
else
  set_param(gcb,'MaskVisibilities',{'on','on','off'});
end
% Note that the value of the bias is not handled here.
% See the Initialization tab
end

4. Double-click the subsystem block Making a Parameter Invisible. Uncheck the Enable Bias parameter and notice that the Bias parameter is invisible.

Disable a Mask Parameter

The subsystem block Disabling a Parameter is referenced in this example. This example shows how to disable a mask parameter based on the value of another mask parameter. The checkbox Enable Bias is used to disable the Bias Value parameter, which is grayed out.

To disable a mask parameter:

1. Create two edit parameters Gain Value and Bias. Create a check box parameter Enable Bias.

2. Use this code in the Initialization section of the Code pane.

function initialization()
% In the Initialization command, the variable 'enableBias' corresponding to
% the checkbox returns the following values:
% unchecked = 0
% checked = 1
If the box is unchecked, we set the bias value to zero
 if ~enableBias
     biasValue = 0;
end
% Othewise, the value from the mask parameter is used
 end

3. Use this code in the parameter callback section for enableBias.

function enableBias_callback()
% Enable and disable parameters
% Get the value of the Enable Bias checkbox
% unchecked = 'off'
% checked = 'on'
 enab = get_param(gcb,'enableBias');
Set the 'MaskEnables' property for each parameters
if strcmp(enab,'on')
    set_param(gcb,'MaskEnables',{'on','on','on'});
else
    set_param(gcb,'MaskEnables',{'on','on','off'});
end
% Note that the value of the bias is not handled here.
% See the Initialization tab
end

4. Double-click the subsystem block Disabling a Parameter. Uncheck the Enable Bias parameter and notice that the Bias parameter is grayed.

See Also

Dynamic Masked Subsystem|