Working with Variant Choices
Each variant choice in your model is associated with a conditional expression called
variant control. The way you specify your variant controls determines the active variant
choice. The Variant control mode parameter available in the block
parameters dialog box allows you to select
Label mode for modeling Variant blocks.
This image shows the block parameters dialog box of a Variant Subsystem block that contains four variant choices:
The first choice is commented out by adding the
%symbol before the variant control.
The second choice is the
(default)and is activated when no variant control evaluates to
The third choice is activated when the expression
mode==3 && version==2evaluates to
The fourth choice is activated when the expression
mode==2 && version==1evaluates to
Default Variant Choice
You can specify at most one variant choice as the default for the model. As shown
in the image above, the
Linear Controller subsystem is defined as
the default variant choice. During model compilation, if Simulink® finds that no variant control evaluates to
uses the default choice.
In the dialog box, select the variant choice and change its Variant
control property to
Active Variant Choice
While each variant choice is associated with a variant control, only one variant
control can evaluate to
true at a time. When a variant control
true, Simulink activates the variant choice that corresponds to that variant control.
At most one variant choice can be active. The active variant cannot be changed once
model is compiled.
In this example, you can activate either the
choice or the
Nonlinear Controller variant choice by specifying
appropriate values for
|Active variant choice
You can specify the values of
version at the MATLAB® Command Window.
Inactive Variant Choice
When a variant control activates one variant choice, Simulink considers the other variant choices to be inactive. Simulink ignores inactive variant choices during simulation. However, Simulink continues to execute block callbacks inside the inactive variant choices.
The color of inactive choices fades by default. You can choose to disable the
fading effect by using the Variant Fading option. The
Variant Fading option is available in the
Information Overlays menu on the
Debug tab of the Simulink Editor. You can use
set_param commands to view or change the fading state of
inactive choices programmatically. For example,
get_param('bdroot','VariantFading') % To view the fading state of inactive choices
set_param('bdroot','VariantFading','on') % To turn on the fading effect of inactive choices
Empty Variant Choice
When you are prototyping variant choices, you can create empty Subsystem blocks with no inputs or outputs inside the Variant Subsystem block. The empty subsystem recreates the situation in which that subsystem is inactive without the need for completely modeling the variant choice.
For an empty variant choice, you can either specify a variant activation condition
or comment out the variant condition by placing a
% symbol before
If this variant choice is active during simulation, Simulink ignores the empty variant choice. However, Simulink continues to execute block callbacks inside the empty variant choices.
List of Variant Choices
You can get a list of variant choices in a Variant Subsystem block
using the read-only parameter
varchoices = get_param(gcb, 'VariantChoices');
In this example, the
VariantChoices parameter returns the
Open Active Variant
When you open a model, variant blocks display the name of the variant that was active the last time that you saved your model. Use the Variant menu to open the active variant. Right-click the block and select Variant > Open. Then select the active variant.
Use this command to find the current active choice:
Use this command to find the path to the current active choice:
CompiledActiveChoiceBlockparameter is supported only for the Variant Subsystem block.
Active variant cannot be changed once the model is compiled.