Main Content

Export, Save, Refresh, and Load a Variant Configuration Data Object

This example shows how to export, save, and load a variant configuration data object for a Simulink® model using Variant Manager.

Learn how to use Variant Manager to:

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

  • Save the variant configuration data object for reuse.

  • Refresh the variant configuration data object.

  • Load the variant configuration data object from a file.

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 variation of a Simulink model. A variant configuration data object (instance of the Simulink.VariantConfigurationData class) stores the collection of all variant configurations defined for a model. For more information, see Create and Validate Variant Configurations.

Open Variant Manager

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

 open_system('slexVariantSubsystems');

2. On the Modeling tab, in the Design section, click Variant Manager.

  • A: Name of variant configuration object

  • B: Configurations tab

  • C: Add variant configuration

  • D: Name of a variant configuration

  • E: Export variant configuration object

  • F: Control Variables tab

  • G: Import control variables

  • H: Add control variable

Define a New Variant Configuration

1. In Variant Manager, in the upper pane of the Configurations tab, click the Add variant configuration button (C). A new variant configuration is added. Enter the name LinearConfiguration for this configuration (D).

2. Click the Control Variables tab (F) in the lower pane of the Configurations tab.

3. To import the control variables to be used for the variant configuration from the global workspace, click the Import control variables button (G). Click the Add control variable button (H) to add new control variables to the model.

4. In the Variant configuration object box (A), type the name vcdo_vssmodel for the variant configuration data object.

Export the Variant Configuration Data Object

To export the variant configuration data object to the global workspace of the model, click the Export variant configuration object button (E). This step also associates the data object to 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 Variant configuration object box to empty and click the Export variant configuration object button (E).

Save the Variant Configuration Data Object for Reuse

When you export the variant configuration data object to the base workspace, it is available only for the current MATLAB session. To permanently store the data, save it in a MAT file or MATLAB script. From the Export variant configuration object button list, select Save As and enter the name of the file to store the object.

Refresh the Variant Configuration Data Object

You can refresh the variant configuration data object from Variant Manager to reflect any changes made from the global workspace. Click inside the Variant configuration object box. From the list, select Refresh.

Load the Variant Configuration Data Object from a File

You can load the variant configuration data object that is stored in a MAT file or MATLAB script from Variant Manager. Click inside the Variant configuration object box. From the list, select Load from file.

See Also