主要内容

Simulink.VariantConfigurations

R2026b

Create and store variant configurations and constraints

Renamed from Simulink.VariantConfigurationData in R2026b

    Description

    Use a Simulink.VariantConfigurations object to store a collection of variant configurations, constraints that must be satisfied by the configurations, and the name of a preferred variant configuration for a model. You can define the variant configurations object in the base workspace or in the Design Data section of a Simulink® data dictionary.

    A variant configuration represents a specific set of variation points across the model hierarchy. It contains a group of variant control variables and their values, which you can use to activate a specific variant in the model hierarchy. A Simulink.VariantConfigurations object enables you to:

    • Define new variant configurations.

    • Add variant control variables to a variant configuration.

    • Define constraints to check for invalid variant configurations.

    • Add or remove association between variant configurations of top-level model and referenced model.

    • Delete existing variant configurations, constraints, and control variables.

    • Set a specific configuration as the preferred variant configuration.

    Creation

    Description

    varconfigdata = Simulink.VariantConfigurations creates an empty VariantConfigurations object.

    varconfigdata = Simulink.VariantConfigurations(PropertyName=Value) creates a VariantConfigurations object and sets its properties using one or more property name-value arguments.

    example

    Properties

    expand all

    This property is read-only after object creation.

    Set of variant configurations in the variant configurations object, specified as a structure or structure array with these fields:

    FieldTypeDescription
    Namecharacter vector or string scalar

    Name of the configuration. The value must be a unique and valid MATLAB® variable name.

    Descriptioncharacter vector or string scalar

    Description of the configuration.

    ControlVariables

    structure or structure array

    Variant control variable names and their values, specified as a structure or structure array with the fields:

    • Name — Name of the control variable, specified as a character vector or string scalar.

    • Value — Value of the control variable, specified as any of these data types:

    • Source — Data source of the control variable, specified as a character vector or string scalar.

    Example: ctrlVarStruct=struct(Name="Ctrl",Value="ControllerType.Linear",Source="plant.sldd");

    Example:ctrlVarStruct=struct(Name="Vctrl",Value="1",Source="base workspace");

    For an example that shows the use of different types of variant control variables, see Use Variant Control Variables in Variant Blocks.

    Data Types: struct

    This property is read-only after object creation.

    Constraints that must be met by all variant configurations in the variant configuration object, specified as a structure or structure array with these fields:

    • Name — Name of the constraint, specified as a character vector or string scalar. The value must be a unique and valid MATLAB variable name.

    • Condition — Boolean expression defined using variant control variables, specified as a character vector or string scalar. The expression must evaluate to true to satisfy the constraint.

    • Description — Description of the constraint, specified as a character vector or string scalar.

    Data Types: struct

    Name of the preferred variant configuration, specified as a character vector or string scalar. Use this property to indicate the configuration that is suited for the model for common workflows. The value must be the name of a variant configuration present in the variant configurations object.

    Data Types: char | string

    Object Functions

    addConfigurationAdd new variant configuration to variant configurations object
    addReferencedConfiguration Associate top-model variant configuration with variant configuration of referenced model
    addConstraintAdd constraint to variant configurations object
    addControlVariablesAdd variant control variables to named variant configuration in variant configuration object
    addCopyOfConfigurationAdd copy of existing variant configuration to variant configurations object
    convertDefaultToPreferredConvert default variant configuration to preferred variant configuration
    getVariantConfigurationGet specific variant configuration from variant configurations object
    getConstraintGet constraint from variant configurations object
    getControlVariableGet variant control variable from variant configuration
    getReferencedConfigurationNameGet name of variant configuration used by referenced component in model hierarchy
    getPreferredConfigurationGet name of preferred variant configuration for variant configurations object
    isConfigActiveCheck if variant configuration is active
    setPreferredConfiguration Set name of preferred variant configuration for variant configurations object
    removeConfigurationRemove variant configuration from variant configurations object
    removeReferencedConfigurationRemove association between variant configurations of top-level model and referenced model
    removeConstraint Remove constraint from variant configurations object
    setConstraintModify condition and description of existing variant constraint
    removeControlVariableRemove variant control variable from variant configuration

    These functions specialize standard MATLAB set operations for Simulink.VariantConfigurations objects.

    intersect

    vcoC = intersect(vcoA,vcoB)

    Find the intersection of variant configuration objects vcoA and vcoB. This function returns a variant configurations object, vcoC, with the common variant configurations present in vcoA and vcoB. The function finds the intersection by matching the variant control variables and their values.

    Constraints in vcoC are formed as follows. Consider the case where vcoA and vcoB have two constraints each.

    • vcoA has constraints constraintA1 and constraintA2.

    • vcoB has constraints constraintB1 and constraintB2.

    Then, vcoC has these constraints:

    • constraintA1 && (constraintB1 && constraintB2)

    • constraintA2 && (constraintB1 && constraintB2)

    The constraint conditions formed by logical AND, OR, and NOT operations are simplified by default and symbols can be reordered.

    vcoC = intersect(vcoA,vcoB,SimplifyConditions=false) returns a variant configurations object vcoC in which constraint conditions are not simplified.

    The remaining properties of vcoC are the same as vcoA, and the data in vcoC appears in the same order as in vcoA.

    setdiff

    vcoC = setdiff(vcoA,vcoB)

    Find the difference between variant configuration objects vcoA and vcoB. This function returns a variant configurations object vcoC that contains configurations that are in vcoA but not in vcoB. The function finds the difference by identifying changes in the values of variant control variables.

    Constraints in vcoC are formed as follows. Consider the case where vcoA and vcoB have two constraints each.

    • vcoA has constraints constraintA1 and constraintA2

    • vcoB has constraints constraintB1 and constraintB2

    Then, vcoC has these constraints:

    • constraintA1 && ~(constraintB1 && constraintB2)

    • constraintA2 && ~(constraintB1 && constraintB2)

    The constraint conditions formed by logical AND, OR, and NOT operations are simplified by default and symbols can be reordered.

    vcoC = setdiff(vcoA,vcoB,SimplifyConditions=false) returns a variant configurations object vcoC in which constraint conditions are not simplified.

    The remaining properties of vcoC are the same as vcoA, and the data in vcoC appears in the same order as in vcoA.

    union

    vcoC = union(vcoA,vcoB)

    Find the union of variant configuration objects vcoA and vcoB. This function returns a variant configurations object vcoC that contains configurations from both vcoA and vcoB, with no duplicates. The function finds the union by matching the variant control variables and their values.

    Constraints in vcoC are formed as follows. Consider the case where vcoA and vcoB have two constraints each.

    • vcoA : constraintA1, constraintA2

    • vcoB : constraintB1, constraintB2

    Then, vcoC has these constraints:

    • constraintA1 || (constraintB1 && constraintB2)

    • constraintA2 || (constraintB1 && constraintB2)

    The constraint conditions formed by logical AND, OR, and NOT operations are simplified by default and symbols can be reordered.

    vcoC = union(vcoA,vcoB,SimplifyConditions=false) returns a variant configurations object vcoC in which constraint conditions are not simplified.

    The remaining properties of vcoC are the same as vcoA, and the data in vcoC appears in the same order as in vcoA, then vcoB.

    unique

    uniquedVCO = unique(vco)

    Find unique configurations in the variant configurations object vco.

    Duplicate configurations in vco are removed by comparing the values of variant control variables. Duplicate constraints in vco are removed by comparing the constraint conditions.

    Examples

    collapse all

    This example shows how to create a Simulink.VariantConfigurations object and set these object properties:

    • Configurations

    • Constraints

    • PreferredConfiguration

    Define New Variant Configuration

    Define a new variant configuration to add to the variant configurations object.

    The Configurations property of a Simulink.VariantConfigurations object is a structure with these fields:

    • Name

    • ControlVariables

    • Description

    Create a structure for the ControlVariables field that contains the variant control variables and values for the new configuration.

    ctrlVarStructA(1).Name = "Ctrl";
    ctrlVarStructA(1).Value = "ControllerType.Linear";
    ctrlVarStructA(1).Source = "topData.sldd";
    ctrlVarStructA(2).Name = "Noise";
    ctrlVarStructA(2).Value = "NoiseType.NoNoise";
    ctrlVarStructA(2).Source = "topData.sldd";
    ctrlVarStructA(3).Name = "PlantLoc";
    ctrlVarStructA(3).Value = "PlantLocation.Internal";
    ctrlVarStructA(3).Source = "topData.sldd";
    ctrlVarStructA(4).Name = "FidType";
    ctrlVarStructA(4).Value = "Fidelity.High";
    ctrlVarStructA(4).Source = "plantData.sldd";

    Create a structure for the new variant configuration.

    configStruct(1).Name = "LinInterExpNoNoise";
    configStruct(1).ControlVariables = ctrlVarStructA;
    configStruct(1).Description = "Linear Internal Plant Controller";

    Define a second variant configuration.

    ctrlVarStructB(1).Name = "Ctrl";
    ctrlVarStructB(1).Value = "ControllerType.Nonlinear";
    ctrlVarStructB(1).Source = "topData.sldd";
    ctrlVarStructB(2).Name = "Noise";
    ctrlVarStructB(2).Value = "NoiseType.NoNoise";
    ctrlVarStructB(2).Source = "topData.sldd";
    ctrlVarStructB(3).Name = "PlantLoc";
    ctrlVarStructB(3).Value = "PlantLocation.External";
    ctrlVarStructB(3).Source = "topData.sldd";
    ctrlVarStructB(4).Name = "FidType";
    ctrlVarStructB(4).Value = "Fidelity.Low";
    ctrlVarStructB(4).Source = "plantData.sldd";
    
    configStruct(2).Name = "NonLinExterLowFid";
    configStruct(2).ControlVariables = ctrlVarStructB;
    configStruct(2).Description = "Nonlinear External Plant Controller";

    Define Constraints

    Define any constraints applicable for all the variant configurations in the variant configurations object.

    constrStruct = struct(Name="PlantLocation", ...
      Condition="(PlantLoc==PlantLocation.Internal) || (PlantLoc==PlantLocation.External)", ...
     Description="Plant location constraint");

    Create Variant Configurations Object

    Create the object by adding variant configurations, constraints, and the name of the preferred configuration.

     varConfigs = Simulink.VariantConfigurations(Configurations=configStruct,Constraints=constrStruct, ...
      PreferredConfiguration="LinInterExpNoNoise")
    varConfigs = 
      VariantConfigurations with properties:
    
                Configurations: [1×2 struct]
                   Constraints: [1×1 struct]
        PreferredConfiguration: 'LinInterExpNoNoise'
    
    

    Associate or Disassociate Variant Configurations Object from Model

    You can associate varConfigs with a Simulink® model using the VariantConfigurations model parameter.

    set_param("model",VariantConfigurations="varConfigs");
    

    To disassociate varConfigs from the model, set the VariantConfigurations model parameter to an empty character vector or string.

    set_param("model",VariantConfigurations="");
    

    Save the model to save your changes.

     save_system("model");
    

    Tips

    You can edit a variant configurations object from the base workspace or data dictionary without launching Variant Manager. Double-click the object in the base workspace or in the Design Data section of the data dictionary in the Model Explorer. This action launches the Simulink.VariantConfigurations property dialog box. This dialog box functions as a standalone variant manager and allows you to modify variant configurations, control variables, and constraints in the variant configurations object.

    Version History

    Introduced in R2013b

    expand all