Main Content

setRule

Create rules that are validated against data at port

Since R2022a

Syntax

consObj.setRule(rule)
consObj.setRule(Name=Value)

Description

consObj.setRule(rule) adds the object of type Simulink.Mask.PortConstraintRule rule to the object.

consObj.setRule(Name=Value) creates a rule using name-value arguments and adds it to port constraint object.

Input Arguments

expand all

Rule object, specified as a Simulink.Mask.PortConstraintRule object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Permitted data types, specified as a cell array. The allowed values are int, double, fixed point and so on.

The allowed values in the array are scalar, vector, 2dmatrix, ndmatrix, rowvector, and colvector.

The allowed complexity, specified as a cell array. The allowed values in the array are real and complex.

Set the Signedness, bias, Wordlength, and Scaling for fixed point data type.

Examples

Set Rules Using ConstraintRule Object

%Get an instance of Simulink.Mask.PortConstraintRule
consObj=Simulink.Mask.PortConstraint;
rule = Simulink.Mask.PortConstraintRule;
pc1.DataType = {'double','int32'};
pc1.complexity = {'real'};
consObj.setRule(rule);

Set Rules as Name-Value Pair Arguments

% Create an instance of Simulink.Mask.PortConstraint to set the rule
constraint.setRule('DataType',{'fixedpoint'},'Dimension',{'scalar'},
'Complexity',{'real'})
ans = 

  PortConstraintRule with properties:

                DataType: {'fixedpoint'}
               Dimension: {'scalar'}
              Complexity: {'real'}
    FixedPointConstraint: [1×1 Simulink.Mask.FixedPointConstraint]
rule = constraint.getRule
rule = 

  PortConstraintRule with properties:

                DataType: {'fixedpoint'}
               Dimension: {'scalar'}
              Complexity: {'real'}
    FixedPointConstraint: [1×1 Simulink.Mask.FixedPointConstraint]
%Define the properties of FixedPointConstraint
rule.FixedPointConstraint.Scaling = "binary";
rule.FixedPointConstraint.Signedness = "unsigned";
rule.FixedPointConstraint.WordLength = "[8:12]";
rule.FixedPointConstraint
ans = 

  FixedPointConstraint with properties:

       Scaling: 'binary'
          Bias: ''
    Signedness: 'unsigned'
    WordLength: '[8:12]'

Version History

Introduced in R2022a