Main Content
addPortConstraint
Class: Simulink.Mask
Namespace: Simulink
Syntax
maskObj.addPortConstraint(pc),
maskObj.addPortConstraint(Name=Value)
Description
maskObj.addPortConstraint(
pc
), maskObj.addPortConstraint(
.
Creates port constraint on a mask object by adding options specified as name-value pair
arguments.Name=Value
)
Input Arguments
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