Main Content

addConstraint

Add constraint to XML file

Since R2023a

    Description

    example

    fileobj.addConstraint(constraint) adds a constraint in XML file format. Constraint is a Simulink.Mask.Constraints object that you must first create by using saveConstraints.

    Examples

    collapse all

    Create a Simulink.Mask.Constraint object to create a parameter constraint.

    constraintObj = Simulink.Mask.Constraints;

    Assign a name to the constraint.

    constraintObj.Name = 'numericconst';

    Add parameter constraint rules to the constraint.

    constraintObj.addParameterConstraintRule('DataTypes',{'numeric'},...
                                             'Fraction',{'integer'});

    Create a Simulink.Mask.SharedConstraintFile object to add constraint to an XML file.

    % fileobj is an object of Simulink.Mask.SharedConstraintFile
    fileobj = Simulink.Mask.SharedConstraintFile;
    fileobj.FileName = "sharedconstraint";
    fileobj.addConstraint(constraint)
    
    ans = 
    
      Constraints with properties:
    
                   Name: 'numericconst'
        ConstraintRules: [1×1 Simulink.Mask.ParameterConstraintRules]
    

    Input Arguments

    collapse all

    Parameter constraint, specified as a Simulink.Mask.Constraints object. Save the constraint using saveConstraints.

    Data Types: cell

    Version History

    Introduced in R2023a