Main Content

addCrossPortConstraint

Class: Simulink.Mask
Namespace: Simulink

Create cross-port constraint among ports of the same masked block

Since R2023a

Syntax

maskObj.addCrossPortConstraint(crossPortConsObj)
maskObj.addCrossPortConstraint(Name=Value)

Description

maskObj.addCrossPortConstraint(crossPortConsObj) creates cross-port constraint by using the object of Simulink.Mask.CrossPorConstraint.

maskObj.addCrossPortConstraint(Name=Value) creates cross-port constraint with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Cross-port constraint object, specified as a Simulink.Mask.CrossPortConstraint object.

Name-Value Arguments

expand all

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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Name of cross-port constraint, specified as a character vector.

Data Types: char | string

Rule for the cross-port constraint, specified as a character vector.

Data Types: char | string

Mask parameter conditions, specified as an object of Simulink.Mask.ParameterCondition.

Associate port identifiers with cross-port constraints, specified as a cell array. Separate identifiers with commas.

Data Types: cell

Type of diagnostic message displayed when validation condition fails, specified as error or warning.

Data Types: char | string

Diagnostic message to display when validation fails, specified as character vector.

Data Types: char | string

Examples

expand all

This example shows how to create cross port constraint programmatically using cross port constraint object and name=value pair arguments.

Create Cross Port Constraint Using Name=Value Pair

Load the model.

open_system('slexMaskingBasic.slx');

Add a mask parameter checkCrossPortDimension.

maskObj= Simulink.Mask.create(gcb);
maskObj.addParameter(Name='checkCrossPortDimension',Type='edit');

Create port identifiers to associate cross port constraint.

maskObj.addPortIdentifier(Name='Input_1',Type='Input',IdentifierType='index',Identifier='1');
maskObj.addPortIdentifier(Name='Input_2',IdentifierType='index',Identifier='2');
maskObj.addPortIdentifier(Name='Output_1',Type='Output',IdentifierType='index',Identifier='1');

Create cross-port constraint.

maskObj.addCrossPortConstraint(Name='CheckDimensions',Rule='SameDimension'...
    ,ParameterConditions={'Name','checkCrossPortDimension','Values',{'on'}},...
    Associations={'Input_1','Input_2'},DiagnosticLevel='error',...
    DiagnosticMessage="The inputs to the masked block must be of same dimensions")
ans = 
  CrossPortConstraint with properties:

                   Name: 'CheckDimensions'
                   Rule: 'SameDimension'
    ParameterConditions: [1×1 Simulink.Mask.ParameterCondition]
           Associations: {2×1 cell}
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'The inputs to the masked block must be of same dimensions'

Create Cross Parameter Constraint Using Object of Simulink.Mask.CrossPortConstraint

Create an instance of Simulink.Mask.CrossPortConstraint

crossPortConst = Simulink.Mask.CrossPortConstraint;

Set the properties of the object.

crossPortConst.Name = 'CheckDatatype';
crossPortConst.Rule = 'SameDataType';
crossPortConst.Associations = {'Input_1','Input_2','Output_1'};
crossPortConst.DiagnosticLevel = 'error';
crossPortConst.DiagnosticMessage = 'The Input_1 and Output_1 should have same DataType';
maskObj.addCrossPortConstraint(crossPortConst)
ans = 
  CrossPortConstraint with properties:

                   Name: 'CheckDatatype'
                   Rule: 'SameDataType'
    ParameterConditions: [0×0 Simulink.Mask.ParameterCondition]
           Associations: {3×1 cell}
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'The Input_1 and Output_1 should have same DataType'

Version History

Introduced in R2023a