This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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. Variant control mode parameter available in the block parameters dialog box allows you to select Expression or 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 true.

  • The third choice is activated when the expression mode==3 && version==2 evaluates to true.

  • The fourth choice is activated when the expression mode==2 && version==1 evaluates to true.

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 true, it uses the default choice.

In the dialog box, select the variant choice and change its Variant control property to (default).

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 evaluates to 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 Model variant choice or the Nonlinear Controller variant choice by specifying appropriate values for mode and version.

Value of modeValue of versionActive variant choice
21Nonlinear Controller
32Model

You can specify the values of mode and 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.

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 the condition.

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.

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:

get_param(gcb,'CompiledActiveChoiceControl')

Use this command to find the path to the current active choice:

get_param(gcb,'CompiledActiveChoiceBlock')

Note

  • The CompiledActiveChoiceBlock parameter is supported only for the Variant Subsystem block.

  • Active variant cannot be changed once the model is compiled.

Related Examples

More About