Main Content

addPortConstraint

Class: Simulink.Mask
Namespace: Simulink

Create port constraint on a mask object

Since R2022a

Syntax

maskObj.addPortConstraint(pc),
maskObj.addPortConstraint(Name=Value)

Description

maskObj.addPortConstraint(pc), maskObj.addPortConstraint(Name=Value). Creates port constraint on a mask object by adding options specified as name-value pair arguments.

Input Arguments

expand all

Port constraint object, specified as a Simulink.Mask.PorConstraint object.

Data Types: char | cell

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.

Name of the constraint specified as a string.

Example: ParameterConditions={ 'Name', 'parameter1', 'Values', {'10','20'}}

sets Parameter Conditions as a Parameter Condition object with a Name of 'parameter1' and Values of {'10', '20'}.

Datatype, complexity, and dimension for the constraint, specified as a cell array.

The type of diagnostic message displayed when validation condition fails specified as error or warning.

The diagnostic message that is displayed when the validation fails, specified as a character vector.

Examples

Create Port Constraint with Mask Object

% Create an instance of Simulink.Mask.ParameterCondition
p1 = Simulink.Mask.ParameterCondition;
p1.Name = 'param1';
p1.Values = {'on'};
p2=Simulink.Mask.ParameterCondition;
p1.Name = 'param2';
p1.Values ={'0','1'};

Create a Simulink.Mask.PortConstraint object, then set its properties using dot notation. Use p1 and p2 as its Parameter Conditions.

pc = Simulink.Mask.PortConstraint;
pc.Name = 'pc1';
pc.ParameterConditions = ['p1','p2'];
pc.Rule.DataType = {'double','int8'};
pc.Rule.Complexity={'real'};
pc.DiagnosticLevel = 'warning';
pc.DiagnosticMessage = 'Invalid data at port';

Get the mask object maskObj, then add the port constraint to it.

maskObj.addPortConstraint(pc);

Create Port Constraint Directly with Name-Value pair Arguments

%Get mask object
aMaskObj = Simulink.Mask.get('model\subsystem');

%Add a port constraint directly using name-value pair arguments
aMaskObj.addPortConstraint('Name','pc3','ParameterConditions',
 { {'Name','parameter1', 'Values', {'10','20'} },
{'Name', 'parameter2', 'Values', {'10','20'} } },
'Rule', {'DataType', {'double','int32'}, 'Complexity', {'real'} } ,
'DiagnosticLevel', 'error','DiagnosticMessage', 'Invalid Data')
ans = 

  PortConstraint with properties:

                   Name: 'pc3'
    ParameterConditions: [1×2 Simulink.Mask.ParameterCondition]
                   Rule: [1×1 Simulink.Mask.PortConstraintRule]
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'Invalid Data'
%Get the Rule object
pc1.Rule
ans = 

  PortConstraintRule with properties:

                DataType: {2×1 cell}
               Dimension: {0×1 cell}
              Complexity: {'real'}
    FixedPointConstraint: [1×1 Simulink.Mask.FixedPointConstraint]

Version History

Introduced in R2022a