Contenido principal

setConstraint

R2026b

Modify condition and description of existing variant constraint

Since R2026b

    Description

    setConstraint(varConfigs,ConstraintName=constraintName,Condition=condition) sets the condition expression for the variant constraint named constraintName in the Simulink.VariantConfigurations object varConfigs. The constraint must already exist in varConfigs. The new condition overwrites any previously set condition.

    example

    setConstraint(varConfigs,ConstraintName=constraintName,Condition=condition,Description=description) also sets the description for the variant constraint. If description is specified as an empty string, the existing description is cleared.

    example

    Examples

    collapse all

    Create a Simulink.VariantConfigurations object and add a constraint with no condition.

    varConfigs = Simulink.VariantConfigurations;
    varConfigs.addConstraint(ConstraintName="PlantLocConstraint");

    Set the condition expression for the constraint.

    setConstraint(varConfigs,ConstraintName="PlantLocConstraint", ...
        Condition="~(PlantLoc == PlantLocation.External)");

    Create a Simulink.VariantConfigurations object and add a constraint.

    varConfigs = Simulink.VariantConfigurations;
    varConfigs.addConstraint(ConstraintName="ControllerPlantConstraint");

    Set both the condition and description for the constraint.

    setConstraint(varConfigs,ConstraintName="ControllerPlantConstraint", ...
        Condition="~((Ctrl == ControllerType.Linear) && (PlantLoc == PlantLocation.External))", ...
        Description="Linear controller must not have an external plant");

    Input Arguments

    collapse all

    Variant configurations object that contains the constraint to modify, specified as a Simulink.VariantConfigurations object.

    Name of the constraint to modify, specified as a character vector or string scalar. The constraint must already have been added to varConfigs by using the addConstraint function.

    Example: "PlantLocConstraint"

    Boolean condition expression that is defined in terms of variant control variables and referenced component configurations, specified as a character vector or string scalar. The expression must evaluate to true to satisfy the constraint.

    Example: "~(PlantLoc == PlantLocation.External)"

    Description of the constraint, specified as a character vector or string scalar. If not specified, the existing description is preserved. If specified as an empty string, the description is cleared.

    Example: "Linear controller must not have an external plant"

    Version History

    Introduced in R2026b