Main Content

Save and Reuse Variant Configurations Using Variant Configuration Data Object

This example shows how to use Variant Manager to save and reuse variant configurations for a Simulink® model using a variant configuration data object.

Learn how to use Variant Manager to:

  • Export a variant configuration data object to the global workspace.

  • Export the variant configuration data object to a file for reuse.

  • Import the variant configuration data object from a file.

  • Reload the variant configuration data object from the global workspace.

Overview of Variant Configurations

A variant configuration allows you to define a named set of variant control variables and their values, which can be used to activate a specific variation of a Simulink model. A variant configuration data object (instance of the Simulink.VariantConfigurationData class) stores the collection of all variant configurations and constraints defined for a model. For more information, see Variant Configurations.

Open Variant Manager

1. Open the model for which you want to create a variant configuration data object. Consider the model slexVariantSubsystems.

 open_system('slexVariantSubsystems');

2. On the Modeling tab, in the Design section, click Variant Manager. The Variant Manager window opens and shows the Manage tab.

Define New Variant Configuration

1. In Variant Manager, in the Configurations tab, click the Add variant configuration button. A new row is added. In the box, enter the name LinearConfiguration.

2. In the Configurations tab, scroll down to see the Control Variables section.

3. To import the control variables for the variant configuration from the global workspace, click the Import control variables across model hierarchy button in the Control Variables section.

4. Click the Add control variable button in the control variables table to add new control variables to this configuration.

5. In the Simulink.VariantConfigurationData text box in the toolstrip, type a name for the variant configuration data object, for example, vcdo_vssmodel.

Export Variant Configuration Data Object to Global Workspace

  • To export the variant configuration data object to the global workspace of the model, click Apply changes in the Variant Manager toolstrip. This step also associates the data object with the model.

  • You can retrieve the variant configuration data object associated with a model using the parameter VariantConfigurationObject. Run this command in the MATLAB® Command Window.

get_param('slexVariantSubsystems','VariantConfigurationObject')
ans =
'vcdo_vssmodel'
  • To disassociate the variant configuration data object from the model, set the Simulink.VariantConfigurationData box to empty and click Apply changes.

Save Variant Configuration Data Object to File for Reuse

When you export the variant configuration data object to the base workspace, it is available only for the current MATLAB session. To store the variant configurations for reuse, save it in a MAT-file or MATLAB script.

1. Click Export to file in the toolstrip.

2. In the Save to file dialog box, enter the name and type of the file to store the object. Click Save.

Load Variant Configuration Data Object from File

You can import a variant configuration data object that is stored in a MAT-file or MATLAB script into Variant Manager.

1. Click Import from file in the Variant Manager toolstrip.

2. In the Import from file dialog box, select the file and click Open.

Reload Variant Configuration Data Object

To reload the variant configuration object from the global workspace used by the model, click Reload object in the Variant Manager toolstrip. This allows you to revert the changes that are not yet exported to the global workspace.

When you export the variant control variables in a variant configuration to the global workspace or when you activate a variant configuration, the corresponding variant control variables are pushed to the global workspace. Reloading the variant configuration object from Variant Manager does not revert these changes.

See Also