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.

Data Types: char | string | 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.

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

Example: 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")

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.

Data Types: char | string

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

new_system('crossportconstraint');
add_block('built-in/subsystem','crossportconstraint/subsystem');
save_system;
open_system('crossportconstraint');
% Create mask
maskObj= Simulink.Mask.create(gcb);
% Add a mask parameter to create parameter condition
maskObj.addParameter(Name='checkCrossPortDimension',Type='edit');
% Create port identifiers to associate it to the cross port constraint
maskObj.addPortIdentifier(Name='Input_1',Type='Input',IdentifierType='index',Identifier='1');
maskObj.addPortIdentifier(Name='Input_2',IdentifierType='name',Identifier='Input_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: [1x1 Simulink.Mask.ParameterCondition]
           Associations: {2x1 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 using dot notation
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: [0x0 Simulink.Mask.ParameterCondition]
           Associations: {3x1 cell}
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'The Input_1 and Output_1 should have same DataType'

save_system;

Version History

Introduced in R2023a