Main Content

Share Parameter Constraints Across Multiple Block Masks

This example shows you how to create a parameter constraint and share it across masks of different blocks in the same model or different models. You can save the parameter constraint in a MAT file and associate the constraint across multiple block masks.

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 input value for the mask parameter satisfies the rules associated with the constraints. For example, consider a masked Subsystem 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 is displayed. For information on mask parameter constraints, see Validating Mask Parameters Using Constraints.

Explore the Model

This model has two subsystem blocks named SharedConstraintBlock1 and SharedConstraintBlock2. The value of the block parameters on each subsystem block must be a real scalar. Instead of creating separate constraints for these blocks, you can create a single constraint in a MAT file and share it across the two subsystem blocks.


Create Shared Constraint

In the example model, refer the shared constraint blocks SharedConstraintBlock1 and SharedConstraintBlock2

To create a shared constraint:

1. Create a mask on the SharedConstraintBlock1 block.

2. Go to Mask Editor and click the Constraints tab.

i. Click New and enter the name for the MAT file as shared.

ii. Now, create the parameter constraint in the MAT file. Click Parameter Constraint and specify the attributes for the constraint. The Constraint Browser helps you to manage shared constraint.

iii. Go to the Parameters & Dialog tab and click the parameter on which the constraint needs to be applied.

iv. Go to Property Editor > Attributes > Constraint and select the MAT file constraint.

Associate Constraint Across Multiple Blocks or Models

To reuse the constraint shared:realScalarPositiveConstraint in the SharedConstraintBlock2 block:

1. Create a mask on the SharedConstraintBlock2 block.

2. To load the constraint, go to Mask Editor > Constraint > Load. Select the MAT file and save the mask.

3. Go to the Parameters & Dialog tab and click the parameter.

4. Go to Property Editor > Attributes > Constraints and select the MAT file.

Validate the Constraint

Provide an invalid value to the parameter using mask dialog. Observe that an error dialog is displayed on Apply.

See Also