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.
varconfigdataObj = Simulink.VariantConfigurationData(
creates a variant configuration data object and sets Properties using one or more
name-value arguments.Name=Value
)
Properties
Configurations
— Set of variant configurations
structure | structure array
Set of variant configurations in the variant configuration data object, specified as a structure array with the following fields:
Field | Type | Description |
---|---|---|
Name | character vector or string scalar | Name of the configuration. The value must be a unique and valid MATLAB® variable name. |
Description | character 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:
Example:
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
— Constraints for variant configurations
structure | structure array
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 totrue
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
PreferredConfiguration
— Name of preferred variant configuration
character vector | string scalar
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
Public Methods
addConfiguration | Add new variant configuration to variant configuration data object |
addComponentConfiguration | Associate top-model variant configuration with variant configuration of referenced model |
addConstraint | Add constraint to variant configuration data object |
addControlVariables | Add variant control variables to named variant configuration in variant configuration data object |
addCopyOfConfiguration | Add copy of existing variant configuration to variant configuration data object |
convertDefaultToPreferred | Convert default variant configuration to preferred variant configuration |
getConfiguration | Get specific variant configuration from variant configuration data object |
getComponentConfigurationName | Get name of variant configuration used by referenced component |
getPreferredConfiguration | Get name of preferred variant configuration for variant configuration data object |
setPreferredConfiguration | Set name of preferred variant configuration for variant configuration data object |
removeConfiguration | Remove variant configuration from variant configuration data object |
removeComponentConfiguration | Remove association between variant configurations of top-level model and referenced model |
removeConstraint | Remove constraint from variant configuration data object |
removeControlVariable | Remove variant control variable from variant configuration |
Specialized Operators and Functions
These methods specialize standard MATLAB operators and functions for objects in this class.
intersect |
Find the
intersection of variant configuration data objects Constraints in
Then,
The constraint conditions formed by logical
The remaining properties of
|
setdiff |
Find the
difference of variant configuration data objects Constraints in
Then,
The constraint conditions formed by logical
The remaining properties of |
union |
Find the union of
variant configuration data objects Constraints in
Then,
The constraint conditions formed by logical
The remaining properties of
|
unique |
Find unique configurations in the variant configuration data object
Duplicate configurations in
|
Examples
Create Variant Configuration Data Object
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 theControlVariables
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 R2013bR2022b: New add-on required
You must install the Variant Manager for Simulink software support package to use this class and its methods.
R2022b: New capabilities
Support for set operations:
You can use the
intersect
,setdiff
,union
, andunique
methods inSimulink.VariantConfigurationData
class to perform set operations on variant configuration data objects. See Specialized Operators and Functions.New
PreferredConfiguration
property:You can set any of the named configurations defined for a model as the
PreferredConfiguration
to indicate the configuration that is suited for the model for common workflows. This configuration is not applied automatically when compiling or simulating a model. You must apply the preferred configuration explicitly on the model, if required.If the variant configuration data object (
vcd
) for your model has an existingDefaultConfiguration
, you can convert it toPreferredConfiguration
using this command:vcd.convertDefaultToPreferred(model);
To apply the
PreferredConfiguration
on your model before compiling or simulating the model, use this command:Simulink.VariantManager.applyConfiguration(model,... vcd.getPreferredConfigurationName());
R2022b: DefaultConfigurationName
and SubModelConfiguration
properties will be removed
The
DefaultConfigurationName
property will be removed. Use thePreferredConfiguration
property instead. Setting a default variant configuration for a variant configuration data object is not recommended. Previously, if you had set a default configuration, compiling or simulating the model automatically activated the default configuration irrespective of the variant control variable values in the base workspace or data dictionary used by the model. Now, this behavior is not applicable and setting theDefaultConfigurationName
property has no effect.If the variant configuration data object (
vcd
) for your model has an existingDefaultConfiguration
, you can convert it toPreferredConfiguration
using theconvertDefaultToPreferred
method.The
SubModelConfiguration
property will be removed. The variant configurations for a top-level model must also define the variant control variables used by any referenced components in the model hierarchy, such as referenced models. This approach helps to maintain a single consistent definition for a variant control across the hierarchy.If the referenced component has named variant configurations of its own, you can use them to set up the corresponding variant control variables in the top-level model configuration. For more information, see Compose Variant Configurations for Top Model Using Referenced Model Configurations.
For existing models with an associated variant configuration object, variant control variables in the referenced model configuration will be automatically migrated to the configuration of the top-level model. You must save the variant configuration object using Variant Manager to fix related warnings.
Scripts that use these properties run with a warning.
R2022b: Methods to be removed
These methods will be removed in a future release. Scripts that use these methods run with a warning.
To be Removed | Recommended Replacement |
---|---|
validateModel | Simulink.VariantManager.activateModel
|
getFor
| Simulink.VariantManager.getConfigurationData |
addSubModelConfigurations | Simulink.VariantConfigurationData.addComponentConfiguration |
removeSubModelConfiguration | Simulink.VariantConfigurationData.removeComponentConfiguration |
getDefaultConfiguration | Simulink.VariantConfigurationData.getPreferredConfiguration |
setDefaultConfigurationName | Simulink.VariantConfigurationData.setPreferredConfiguration |
R2022b: Change in the format of errors output argument of validateModel
method
The fields Type
, Source
,
PathInModel
, and PathInHierarchy
have been removed
from the structure named Errors
within the second output argument,
errors
. For an example, see Compatibility Considerations When Using Variant Manager for Simulink Support Package.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)