Main Content

addPortConstraint

R2026b

Class: Simulink.Mask
Namespace: Simulink

Create port constraint using mask object

Since R2022a

Description

maskObj.addPortConstraint(portConstraintObj) creates a port constraint by using a mask object.

maskObj.addPortConstraint(Name=Value) creates a port constraint by using a mask object with options specified as name-value arguments.

example

Input Arguments

expand all

Block mask handle, specified as a mask object. You can use the Simulink.Mask.get command to get the block mask handle. For more information, see Simulink.Mask.get

Port constraint object, specified as a Simulink.Mask.PortConstraint 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 constraint, specified as a string or a character vector.

Parameters and their values, specified as a cell array or a vector of Simulink.Mask.ParameterCondition objects.

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

Data type, complexity, and dimension of the constraint, specified as a cell array or a vector of Simulink.Mask.PortConstraintRule objects. For more information, see Port Constraint Options.

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

Diagnostic message that is displayed when validation condition fails, specified as a character vector.

Output Arguments

expand all

Handle to the mask port constraint, returned as a Simulink.Mask.addPortConstraint object.

Examples

expand all

Create a model and add a subsystem block.

open_system(new_system("addPortConstraintExample"));
add_block("built-in/subsystem","addPortConstraintExample/subsystem");

Create a mask object for the subsystem.

maskObj = Simulink.Mask.create(gcb);

Create a mask parameter named TemperatureScale of type popup.

maskObj.addParameter(Type="popup", Name="TemperatureScale", TypeOptions={"Celsius", "Fahrenheit", "Kelvin"});

Define the parameter conditions for TemperatureScale.

TempScaleCondition = Simulink.Mask.ParameterCondition;
TempScaleCondition.Name = "TemperatureScale";
TempScaleCondition.Values = {'Fahrenheit'};

Create and add a port constraint for specific numeric types, double and int32.

DoubleInt32PortConstraint = Simulink.Mask.PortConstraint;
DoubleInt32PortConstraint.Name = "TemperatureInputSpecific";
DoubleInt32PortConstraint.ParameterConditions = [TempScaleCondition];
DoubleInt32PortConstraint.Rule.DataType = {'double', 'int32'};
DoubleInt32PortConstraint.Rule.Complexity = {'real'};
DoubleInt32PortConstraint.DiagnosticLevel = "error";
DoubleInt32PortConstraint.DiagnosticMessage = "Temperature (in Fahrenheit) must be double or int32.";
maskObj.addPortConstraint(DoubleInt32PortConstraint);
DoubleInt32PortConstraint = 

  PortConstraint with properties:

                   Name: 'TemperatureInputSpecific'
    ParameterConditions: [1×1 Simulink.Mask.ParameterCondition]
                   Rule: [1×1 Simulink.Mask.PortConstraintRule]
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'Temperature (in Fahrenheit) must be double or int32.'

Create and add a port constraint for any numeric type.

NumericPortConstraint = maskObj.addPortConstraint('Name','TemperatureInputNumeric',...
'ParameterConditions',{'Name','TemperatureScale','Values',{'Celsius'}},...
'Rule',{'DataType',{'numeric'},'Complexity',{'real'}},...
'DiagnosticLevel','error','DiagnosticMessage','Temperature (in Celsius) must be numeric');
save_system;
NumericPortConstraint = 

  PortConstraint with properties:

                   Name: 'TemperatureInputNumeric'
    ParameterConditions: [1×1 Simulink.Mask.ParameterCondition]
                   Rule: [1×1 Simulink.Mask.PortConstraintRule]
        DiagnosticLevel: 'error'
      DiagnosticMessage: 'Temperature (in Celsius) must be numeric'

Version History

Introduced in R2022a

expand all