Main Content

addCrossPortParameterConstraint

Class: Simulink.Mask
Namespace: Simulink

Create cross port parameter constraint between ports and parameters of same masked block

Since R2025a

Syntax

maskObj.addCrossPortParameterConstraint(crossPortParamConsObj)
maskObj.addCrossPortParameterConstraint(Name=Value)

Description

maskObj.addCrossPortParameterConstraint(crossPortParamConsObj) creates cross port parameter constraint by using the object of Simulink.Mask.CrossPortParameterConstraint.

maskObj.addCrossPortParameterConstraint(Name=Value) adds cross port parameter constraint with options specified by one or more name-value pair arguments and add the constraint to the mask object.

Input Arguments

expand all

Cross port parameter constraint, specified as Simulink.Mask.CrossPortParameterConstraint 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.

Name of the cross port parameter constraint, specified as string.

Example: Name="checkDataType"

Data Types: string | char

Rule associated with the cross port parameter constraint, specified as string.

  • None:— No specific rule or requirement is defined between the port and the parameter.

  • Same DataType:— The data type of the port and the parameter must match.

  • Same Dimension:— The dimension (e.g., scalar, vector, matrix) of the port and the parameter must be identical.

  • Same Complexity:— The complexity, for example: real vs. complex numbers of the data at the port and the parameter must be the same.

Example: Rule="SameDimension"

Data Types: string | char

Parameter conditions for the cross port parameter constraint, specified as cell array. The cross port parameter constraint is active on the associated ports and parameters only when it satisfies the parameter conditions.

Example: crossPortParamConsObj.ParameterConditions={'Name', {'Speed'}, 'Values', {'10','20'}}

Data Types: cell

Option to associate cross port parameter constraint between the mask parameters and port identifiers, specified as Simulink.Mask.CrossPortParameterAssociation object.

Example: Associations={'Parameters', {'Torque'}, 'PortIdentifiers', {'Input_1','Input_2'}}

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

Example: DiagnosticLevel="error"

Data Types: string | char

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

Example: DiagnosticMessage="The input port and parameter must be of same data type"

Data Types: string | char

Examples

Create Cross Port Parameter Constraint

Create cross port parameter constraint and associate them among mask parameters and ports of the same block.

Load the model and get the mask object of the block mx + b.

model = "slexMaskingBasic.slx";
load_system(model);
maskObj = Simulink.Mask.get("slexMaskingBasic/mx + b");

Create a mask parameter Speed and Torque.

maskObj.addParameter(Name="Speed",Type="edit");
maskObj.addParameter(Name="Torque",Type="edit");

Create port identifiers for the ports.

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

Add Cross Port Parameter Constraint Using Mask Object

Add cross port parameter constraint.

maskObj.addCrossPortParameterConstraint(...
    Name="CheckDataType", ...
    Rule="SameDataType", ...
    Associations = {"Parameters", {'Torque'}, "PortIdentifiers", {'Input_1','Output_1'}}, ...
    DiagnosticLevel="error", ...
    DiagnosticMessage="The input port and parameter must be of the same datatype")
ans = 
  CrossPortParameterConstraint with properties:

                   Name: 'CheckDataType'
                   Rule: 'SameDataType'
    ParameterConditions: [0×0 Simulink.Mask.ParameterCondition]
           Associations: [1×1 Simulink.Mask.CrossPortParameterAssociation]
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'The input port and parameter must be of the same datatype'

Add Cross Port Parameter Constraint Using Simulink.Mask.CrossPortParameterConstraint Object

Create cross port constraint from a Simulink.Mask.CrossPortParameterConstraint object.

crossPortParamConsObj = Simulink.Mask.CrossPortParameterConstraint;
crossPortParamConsObj.Name = "CheckDimension";
crossPortParamConsObj.Rule = "SameDimension";
crossPortParamConsObj.DiagnosticLevel = "error";
crossPortParamConsObj.DiagnosticMessage = "The input port and parameter must have same dimension";

Associate cross port parameter constraint to parameters and port identifiers using Simulink.Mask.CrossPortParameterAssociation object.

% assoc = Simulink.Mask.CrossPortParameterAssociation;
% assoc.Parameters = {"Speed"};
% assoc.PortIdentifiers = {"Input_1"};

% crossPortParamConsObj.Associations = assoc;

Alternatives

You can also create cross port parameter constraint from the Mask Editor.

Version History

Introduced in R2025a