Variant Manager Overview
The Variant Manager is a central tool that allows you to manage various variation points that are modeled using variant blocks in a system model or variant transitions in a Stateflow® chart.
A model hierarchy may contain several variant blocks, each with many variant choices, combinations of which correspond to particular configurations of the system. Switching between variant choices and validating them manually can be complicated and erroneous.
Use the Variant Manager to create predefined configurations for a model, and use the model under any of the configurations. You can create the configurations by combinations of different variant choices across the model hierarchy.
Using the Variant Manager, you can:
Define, validate, and visualize variant configurations.
Define and validate constraints for the model.
Specify the default active configuration.
Set control variables to either integer, enumeration values, or
Simulink.Parameter
objects.Associate
Simulink.VariantConfigurationData
object with the model.Validate a variant configuration or model without updating the model.
Reduce a model to retain subset of variant configurations.
Analyze variant configurations.
For information on analyzing variant configurations from Variant Manager, see Analyze Variant Configurations in Models Containing Variant Blocks. For information on analyzing variant configurations from command line, see
Simulink.VariantConfigurationAnalysis
.
Consider the model Variant Management. To open the Variant Manager, you can:
Right-click the variant badge and select Open in Variant Manager.
Right-click the variant block, and select Variant > Open in Variant Manager.
Select the variant block, for example Variant Subsystem block, and then in the Variant Subsystem tab of toolstrip select Variant Manager.
In the Modeling tab of toolstrip, open Design section, click Variant Manager.
Click Open block in Variant Manager available on the variant block’s Block Parameter dialog box.
The Variant Manager window is divided into three panes:
The Variant Configuration Data pane which enables you to define variant configurations and constraints, and export them in variant configuration data object.
The Model Hierarchy pane which enables you to visualize the variant hierarchy.
The Log pane which displays information on the source of control variables and validation errors.
Variant Configuration Data
Use this pane to create configurations, define control variables, associate referenced model configurations, and define constraints. The configurations and associated data are stored in a variant configuration data object.
Variant Configuration Object
After you add a variant configuration, type a name for the variant
configuration object in the Variant configuration object
box. You can use the drop-down menu to load a variant configuration object from
a file or refresh a loaded variant configuration object. You can load a variant
configuration object either from a MAT
file or a MATLAB
script (.m
file). To store the variant configuration object
in the model, global workspace and associate it with the model, click
Export
. To store the variant configuration object in
a folder of your choice either as a
MAT
-file or a MATLAB
script (.m
file), click Save As from the
drop-down menu of the Export button.
Configurations
The Configurations tab is divided into upper and the lower panes. You can use the upper pane to add, delete, or copy a variant configuration. You can also set a default configuration. When you set a configuration to be default configuration, validating or updating the model activates the variant choice specified in the default configuration.
The upper pane has these buttons to manage a variant configuration.
Button | Description |
---|---|
![]() | Add variant configuration |
![]() | Delete variant configuration |
![]() | Duplicate variant configuration |
![]() | Set/Clear default active configuration |
After a variant configuration is added, you can use the lower pane on the Configurations tab to add a description, control variables, and the submodel configurations for it. You can add control variables and export them to the global workspace even when a variant configuration is not added. The lower pane contains these tabs:
Description — Provide a description for the selected variant configuration.
Control Variables — Add, delete, copy or import control variables. Toggle data type and import control variables from the workspace. Show, hide usage of selected control variables.
Button Description Add control variable
Delete the selected control variable
Create a copy of the selected control variable
Toggle type of a control variable
A control variable can be either a plain MATLAB variable or a
Simulink.Parameter
object.Edit
Simulink.Parameter
control variables. This option gets activated when the selected control variable is aSimulink.Parameter
object.Note
To specify
Simulink.Parameter
control variable as an expression, set the Value property of the parameter object by using an equals sign (=) followed by a mathematical expression. For example, enter = A + B.Import control variables from entire model reference hierarchy
Note
Control variables from blocks in
Label
mode are not imported, as they are not variant control variables.Show usage of selected control variables
Hide usage of selected control variables
This table lists the icons used to represent different types of control variables in the Control Variables tab.
Control Variable Icon Type of Control Variable Normal MATLAB® variable Simulink.Parameter
Simulink.VariantControl
with value as normal MATLAB variableSimulink.VariantControl
with value asSimulink.Paramater
The control variables usage is computed on an on-demand basis, where you can choose to show or hide the control variable usage in the model hierarchy table of the Variant Manager.
To do so, in the Variant Manager window, right-click the required control variable and select Show usage or Hide usage. A sample screenshot is as shown.
Submodel Configurations — Define variant configuration for a referenced model.
Add
or delete
a referenced model configuration.
Activate a Variant Configuration
To activate the model for a variant configuration, select a configuration from the list in the Configurations tab and click Activate.
You can activate either of these variant configurations:
The global workspace configuration — Activation is based on the control variables that are currently in the global workspace. You can also add control variables to the table in the Control Variables tab. Activation pushes these variables to the global workspace.
A named variant configuration — Activation is only based on the values of control variables defined in the configuration. This operation also pushes the control variables to the global workspace.
When you open the Variant Manager for a parent model that contains referenced
models, only the parent model is activated. The referenced models are activated
only when you activate the model or expand (click +
) the
reference models in the model hierarchy.
Differences Between Variant Manager Activation and the Update Diagram Process
Activation of a variant configuration using Variant Manager or using the
validateModel
method differs
from the update diagram process that Simulink® performs before simulation or when you update the diagram while
editing the model (Ctrl+D).
Activation using Variant Manager analyzes variant elements in the model such
as variant blocks or variant transitions individually. Variant Manager does not
analyze activeness information based on block connectivity and variant condition
propagation. The activation process validates that the variant elements and the
variant configuration are set up correctly and then activates the configuration
for the model. For example, for a variant block with Variant control
mode set to expression
, the process
evaluates the variant controls on the block and checks if the control variables
used by the block are present in the variant configuration.
Limitations
The tool reports errors and warnings related to variant elements only.
Variant Manager does not support variant controls defined in
InitFcn
callbacks and mask workspaces.Variant Manager does not support workflows such as activation, viewing, or importing of control variables from variations inside a protected model. These variations are present when variant control variables of variant blocks with startup activation time are specified as
TunableParameters
(Simulink Coder) while creating the protected model.
Constraints
Use the Constraints tab to add or delete the model-level constraints. Similar to the Configurations tab, the Constraints tab also contains upper and lower panes.
The upper pane displays the name and condition of the constraints while the lower pane displays the description. The condition expression of the constraint must be satisfied by all variant configurations in the model.
Model Hierarchy
You can visualize and explore the variant hierarchy of a model and edit the properties of variant blocks, variant choices, and variant objects from the Model hierarchy pane. This pane displays the Name, Submodel Configuration, Variant Control, and associated Conditions of variant objects used as variant controls.
Browse the hierarchy using the navigation icons. The controls on the Model hierarchy pane allow you to perform the following actions:
Refresh and validate hierarchy.
Display only variant blocks.
Navigate among variable usage, active choices, invalid choices, and overridden variant choices.
View Blocks
Selectively display blocks in the variant hierarchy:
Select all variant to display all variant blocks.
Select label mode to display variant blocks in
Label
mode and other Model blocks. Variant blocks inExpression
mode, which contains blocks inLabel
mode within their hierarchy are also displayed.Select expression mode to display variant blocks in
Expression
mode and other Model blocks. Variant blocks inLabel
mode, which contains blocks inExpression
mode within their hierarchy are also displayed.Select hierarchical to display all hierarchical blocks (for example, Subsystems, Model blocks) in the model.
Select sim codegen switching mode to display variant blocks in
sim codegen switching
mode.
Navigate
Navigate among variable usage, active choices, invalid choices, and overridden choices:
Variable usage— selects the previous/next rows in the model where the selected control variable is used.
Active choices— selects the previous/next rows in the model having active variant choices.
Invalid choices— selects the previous/next rows in the model having invalid variant choices.
Hierarchy Table
The model hierarchy is displayed in a tree, with each block representing a node in the hierarchy. The hierarchy displays active, inactive, overridden, and invalid variants. You can edit referenced model configurations, variant controls, and variant conditions. Expand nodes to view the underlying blocks.
Note
Protected reference models cannot be viewed in the hierarchy.
The hierarchy table consists of these columns:
Name — Name of the model or block.
Submodel Configuration — Configurations used by referenced models. You can only edit the Submodel Configuration for rows that display models referenced by the top model.
Variant Control — Variant control parameter of a variant choice. This column is identical to the Variant Control column of the parameter dialog box of variant blocks. You can edit this column for variant choices across the hierarchy.
Condition — Displays and allows you to edit the condition for the
Simulink.Variant
object when it is used as variant control. You can edit this column for variant choices across the variant hierarchy.
In the hierarchy table, you can Right-click a block and use one of these options from the context menu, as appropriate:
Open and Highlight Block: Highlights the selected block in the model while displaying selected block location from the top model.
Open Model: Opens the selected model while displaying selected model location from the top-model. This option is available only when you select a model from the hierarchy table.
Open Block Parameters: Opens the block parameter dialog box for the selected block. You can choose to modify the parameter values.
Open Parent Block Parameters: Opens the block parameter dialog box for the parent block of the selected block. You can choose to modify the parameter values.
Set as Label Mode Active Choice: Sets the selected choice of Variant Subsystem, or Variant Sink, or Variant Source blocks as active choice. This option is available only for the Variant Subsystem, or Variant Sink, or Variant Source blocks in label mode.
In the model hierarchy section, each block is represented with an icon. The following table displays the icons and the corresponding block name.
Icon | Block Name |
---|---|
Model Block | |
Inline Variants Block (Variant Source and Variant Sink) | |
Variant Subsystem block | |
Subsystem block | |
Variant Model block | |
Subsystem Reference block | |
Simulink Function block | |
Trigger Port block | |
Stateflow chart block | |
Variant Sink output port | |
Variant Source input port | |
Variant Subsystem block with Propagate conditions outside of variant subsystem option selected. | |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Variant activation time set to
| |
Variant Subsystem block with
Allow zero active variant controls
and Variant activation time set to
| |
Variant Subsystem block with
Allow zero active variant controls
and Variant activation time set to
| |
Variant Subsystem block with
Allow zero active variant controls
and Variant activation time set to
| |
Variant Subsystem block with
| |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem and Variant activation
time set to | |
Variant Subsystem block with
Propagate conditions outside of variant
subsystem option selected. Also,
| |
Inline Variants Block (Variant Source and Variant Sink) with Allow zero active variant control option selected. | |
Inline Variants Block (Variant Source
and Variant Sink) with
| |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to | |
Inline Variants Block (Variant Source
and Variant Sink) with Allow zero
active variant control and Variant
activation time set to | |
Initialize Function block | |
Event Listener block of Initialize Function block | |
Reset Function block | |
Event Listener block of Rest Function block | |
Terminate Function block | |
Event Listener block of Terminate Function block | |
Stateflow chart with Generate preprocessor conditionals option selected. | |
Stateflow transition with Treat as Variant Transition option selected. |
Log
The Log pane displays information and validation results of the source of control variables for the models in the hierarchy.
For example, if a variant configuration is used for a referenced model, the referenced model name is displayed in the row along with name of the variant configuration data object and variant configuration. The pane also displays errors encountered during validation of the variant configuration.
Related Examples
- Create and Validate Variant Configurations
- Import Control Variables to Variant Configuration
- Define Constraints
- Code Generation Using Variant Transitions (Stateflow)