Main Content

Validating Mask Parameters Using 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.

Create and Associate a Constraint

Launch Constraint Manager

Mask Editor contains a Constraint Manager with attributes and options to create your constraints. You can launch the Constraint Manager in two ways:

  • Click the Constraint Manager button in Mask Editor

  • While editing a parameter, select Add New Constraint from the Constraint drop-down menu under Property Editor.

Create a Constraint

You can create constraints according to your specification using the built-in attributes in the Constraint Manager. To create a constraint:

  1. In the Constraint Manager, click Create Constraint.

  2. Select attributes for the constraint in the Rule section. Depending on the data type selected the rule attributes change.

    For more details on rule attributes, see Rule Attributes in Constraint Manager.

  3. Click Apply to create the constraint.

Associate the Constraint to a Mask Parameter

Once a constraint is created, you can associate it with any Edit or Combobox parameters in the Mask Editor.

  1. In the Mask Editor, select the parameter you want to associate a constraint with.

  2. Select the constraint name from the Constraint drop-down menu.

  3. Click Apply to associate the constraint.

Validate the Constraint

To check if the parameter is in adherence with the associated constraint:

  1. Select a parameter with a constraint associated with it.

  2. Provide the input values for the parameter in the Property editor. If the input is outside the specification for the associated constraint, an error displays.

Create a Cross-Parameter Constraint

Cross-parameter constraints are applied among two or more Edit or Combobox type mask parameters. You can use a cross parameter constraint when you want to specify scenarios such as, Parameter1 must be greater than Parameter2.

  1. Launch Constraint Manager.

  2. Click the Cross-Parameter Constraints tab.

  3. Click Create Constraint. A new cross-parameter constraint is created with a default name (Constraint_1). You can change the constraint name.

  4. Specify the following values for the new constraint:

    • Name – Specify a name for the constraint

    • MATLAB Expression – Specify a valid MATLAB expression. This expression is evaluated during edit time and simulation

    • Error Message – Specify the error message to be displayed when the constraint rule is not met. If no error message is specified, a default error message displays.

  5. Click Apply.

Rule Attributes in Constraint Manager

Rule attributes available in the Constraint Manager to create constraints are shown in the table:

Rule AttributeAttribute ValueDescription

Data type

double, single, numeric, integer, int8, uint8, int16, uint16, int32, uint32, int64, uint64, boolean, enum, fixdt, string, half

Specify the acceptable data type of the mask parameter value. For example, if the data type specified is uint8, the acceptable value is in the range of uint8, that is, 0–255.

Complexity

real, complex

Specify if the mask parameter value can be a real or complex number.

Dimensions

scalar, row vector, column vector, 2-D matrix, n-D matrix

Specify the acceptable dimensions for the mask parameter.

Sign

positive, negative, zero

Specify if the input value can be positive, negative, or zero.

Finiteness

finite, inf, -inf, NaN

Specify the acceptable finiteness of mask parameter value.

Range

Minimum, Maximum

Specify the acceptable range of mask parameter value.

Custom Constraint

Valid MATLAB expression

Specify custom constraint for the mask parameter using a valid MATLAB expression. You can use the value token to parameterize the expression. During validation, the evaluated value of the parameter replaces the value token.

Custom Error Message

Character vector

Specify a custom error message for the custom constraint. You can specify the error message as character vector or as a message catalog ID.

Related Topics