Main Content

Customize Mask Parameter Constraints

A mask can contain parameters that accept user input values. You can provide input values for mask parameters using the mask dialog box. Mask parameter constraints help you to create validations on a mask parameter without having to write your own validation code. Constraints ensure that the input for the mask parameter is within a specified range. For example, consider a masked Gain block. You can set a constraint where the input value must be between 1 and 10. If you provide an input that is outside the specified range, an error displays. If you are not able to create a constraint with the built-in attributes, you can create your own constraints using a MATLAB expression.

Explore Model

The example model contains a subsystem block whose block parameters evenNoParam1 and evenNoParam2 must be an even number. This constraint must be customized using a MATLAB expression.


Create Custom Constraint

To create a custom constraint:

1. Create a mask on the subsystem block.

2. In the Mask Editor, select Constraints > Parameter Constraint.

i. Enter the name of the constraint as evenNumberConstraint.

ii. Enter the MATLAB expression as mod(value,2)==0.

Note: You can use the value token to parameterize the expression, which helps in assigning a constraint to multiple parameters. During validation, the evaluated value of the parameter replaces the value token. For example, if the MATLAB expression for a constraint is value > 100 and is associated with the edit type mask parameter, Parameter1, then the MATLAB expression evaluates as Parameter1 > 100. This helps in assigning the constraint to multiple parameters.

iii. In Error Message, enter The value of the parameter must be even number.. Save the mask.

Associate Custom Constraint to Mask Parameters

You must associate constraints to mask parameters. You can associate the same constraint among multiple mask parameters.

1. In the Mask Editor, click the Parameters & Dialog tab.

2. Click the mask parameter.

3. In the Property Editor, go to the Attributes section, and select the constraint from the Constraint.

Note: You can associate the same constraints with multiple mask parameters. The Constraints Browser helps you to manage shared constraints. If you want to create a constraint that involves multiple parameters, use cross-parameter constraints instead of custom constraints.

Validate Constraint

To check if a parameter adheres to the associated constraint:

1. Go to the Mask Editor and select the parameter.

2. In the Property Editor, provide input values that are outside of the range specified in the associated constraint. An error displays.

Related Topics