Main Content

Simulink.VariantConfigurationData class

Package: Simulink

Create variant configurations programmatically

Description

Note

This class requires Variant Manager for Simulink®.

Use the Simulink.VariantConfigurationData class to create a variant configuration data object that stores a collection of variant configurations, constraints, and the name of a preferred variant configuration for a model. You can define the object in the base workspace or in the Configurations section of a data dictionary. The class has methods that enable you to:

  • Define new variant configurations.

  • Add variant control variables to variant configurations.

  • Create a copy of a variant configuration.

  • Define constraints to check for invalid variant configurations.

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

  • Set a specific configuration as the preferred variant configuration.

Creation

Description

varconfigdataObj = Simulink.VariantConfigurationData creates an empty variant configuration data object.

example

varconfigdataObj = Simulink.VariantConfigurationData(Name=Value) creates a variant configuration data object and sets Properties using one or more name-value arguments.

Properties

expand all

Set of variant configurations in the variant configuration data object, specified as a structure array with the following 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:

    • Normal MATLAB variable

    • Simulink.Parameter

    • Simulink.VariantControl whose Value is a normal MATLAB variable

    • Simulink.VariantControl whose Value is a Simulink.Parameter

  • Source — Source of the control variable, specified as a character vector. Source must be 'base workspace' or the name of a data dictionary.

Example: ctrlVarStruct=struct(Name='ControllerType.Linear',Value='NoiseType.NoNoise',Source='plant.sldd');

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

Attributes:

GetAccess
public
SetAccess
private

Data Types: struct

Constraints that must be met by all variant configurations in the variant configuration data object, specified as a structure array with the 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.

Attributes:

GetAccess
public
SetAccess
private

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 configuration data object.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

Methods

expand all

Examples

collapse all

This example shows how to create an instance of the Simulink.VariantConfigurationData class and set these class properties:

  • Configurations (struct)

  • Constraints (struct)

  • PreferredConfiguration (char)

Define New Variant Configuration

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

The VariantConfigurations property in the Simulink.VariantConfigurationData class has these fields:

  • Name (char)

  • ControlVariables (struct)

  • Description (char)

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

ctrlVarStruct = struct(Name='ControllerType.Linear',Value='NoiseType.NoNoise',Source='plant.sldd');
  • Create a struct for the new variant configuration.

configStruct = struct(Name='LinInterExpNoNoise',ControlVariables=ctrlVarStruct, ...
 Description='Linear Internal Experimental Plant Controller');

Define Constraints

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

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

Create Variant Configuration Data Object

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

 vcdo = Simulink.VariantConfigurationData(Configurations=configStruct,Constraints=constrStruct, ...
 PreferredConfiguration='LinInterExpNoNoise')
vcdo = 
  VariantConfigurationData with properties:

            Configurations: [1x1 struct]
               Constraints: [1x1 struct]
    PreferredConfiguration: 'LinInterExpNoNoise'

Associate or Disassociate Variant Configuration Data Object from Model

You can associate vcdo with a Simulink® model using the VariantConfigurationObject model parameter.

set_param('model','VariantConfigurationObject','vcdo');

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

set_param('model','VariantConfigurationObject','');

Save the model to save your changes.

 save_system('model');

Tips

You can edit a variant configuration object from the base workspace or data dictionary without launching Variant Manager. Double-click the object that is present in the base workspace or in the Configurations section of the data dictionary in the Model Explorer. This action launches the Simulink.VariantConfigurationData 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 configuration object.

Version History

Introduced in R2013b

expand all