Define, Activate, and Manage Design Alternatives in Simulink Model
R2026bYou can use variant mechanisms in variant blocks and variant parameters to define, activate, and manage design alternatives. These mechanisms include variant choice, variant control variables, variant activation time, variant condition propagation, and so on. By using these mechanisms, Simulink® models can automatically select and apply the appropriate configuration for any given scenario. This approach enables the models to adapt to changing requirements and streamlines workflows, eliminating the need for manual intervention.
Define Design Alternatives Using Variant Choices
A variant choice is one of the design alternatives or implementations within a variant block or variant parameter in Simulink that can be selected without altering the overall model structure.
In variant blocks, variant choices provide structural variation, with each choice representing a different design alternative. For variant parameters, variant choices enable variation in parameter value, with each choice specifying a different parameter value within a block. You can activate or deactivate each variant choice by using variant controls.
To define variant choices in variant blocks, see Working with Variant Choices. To define variant choices in variant parameters, see Create a Simple Variant Parameter Model.
Switch Between Variant Choices Using Variant Controls
Each variant choice in a variant block or variant parameter is associated with a variant control that determines which variant choice is active. You use the variant control to activate or deactivate a specific variant choice. While each variant choice is associated with a variant control, only one variant choice within a variant block or a variant parameter can be active at any given time. During simulation, Simulink uses only the active variant choice and ignores inactive ones.
For variant blocks, use the Variant control mode parameter to
specify how Simulink determines the active variant choice. In expression
mode, use Boolean expressions to activate a variant choice. In
label mode, use user-defined labels to activate a variant
choice. In sim codegen switching mode, use the
sim and codegen keywords to activate the variant
choice when performing simulation and code generation workflows, respectively.
For variant parameters, only the expression type of variant
control mode is supported, so you use Boolean expressions to activate variant
choices.
| Variant control mode | Description |
|---|---|
expression | Simulink uses Boolean expressions to determine the active variant choice. The
value of the variant control variable specifies which variant becomes active.
Simulink activates the selected variant at the simulation or code generation
phase defined by Variant activation time. Use
|
label | Simulink uses descriptive, predefined strings, called
labels, that you assign during model creation or editing
to select the active variant choice. Use |
sim codegen switching | Simulink automates variant selection between two variant choices based on
whether you are running a simulation or generating code task. To control which
variant is active, assign the keyword |
For more information on variant control modes, see Variant Control Modes in Variant Blocks and Variant Control Mode in Variant Parameters.
Select Active Choice Using Variant Control Variables
A variant control variable is a workspace variable
used in Boolean variant control expressions of a variant block or variant parameter. To
specify a variant control variable for a variant block, set Variant control
mode to expression. For a variant parameter,
expression is the only available variant control mode. The
value of the variant control variable determines which variant control expression evaluates
to true to activate the corresponding variant choice. By changing the
values of variant control variables, you can switch between variant choices without altering
the overall model structure. You can define the variant control variables in different
workspaces, such as the base workspace, model workspace, or data dictionary based on your
requirements. For more information, see Switch Between Choices Using Condition Expressions in Variant Blocks and Switch Between Choices Using Condition Expressions in Variant Parameters.
This model represents a vehicle system with a Variant Subsystem block
Engine and a variant parameter kv. The
Engine block has three variant choices
Engine_2_cyl_petrol, Engine_4_cyl_petrol, and
Engine_8_cyl_petrol which represent three possible engine
configurations. You can switch between these subsystems based on the value of the variant
control variable EngineType.
Engine_2_cyl_petrolis active whenEngineType == 1evaluates totrueEngine_4_cyl_petrolis active whenEngineType == 2evaluates totrueEngine_8_cyl_petrolis active whenEngineType == 3evaluates totrue
The variant parameter kv stores multiple values of
throttle, and you can switch between these values based on the value of the variant control
variable nc.
Throttle is
10whennc == 1evaluates totrueThrottle is
20whennc == 2evaluates totrue
During simulation, the selected throttle value is input to the chosen engine
configuration. If the value of EngineType is 1 and the
value of nc is 2, a throttle value of
20 is provided as an input to the
Engine_2_cyl_petrol subsystem.

Automatically Identify Variant Paths Using Variant Condition Propagation
Simulink determines which model components are active during model compilation through a process called variant condition propagation. This process evaluates the variant controls specified on variant blocks and automatically propagates the variant conditions to the connecting blocks. Variant conditions can propagate through signal lines, buses, and function calls. This process deactivates model components associated with the inactive variant choices, and those model components are excluded from simulation. See Propagate Variant Conditions from Variant Blocks Upstream and Downstream.
This section explains how the variant conditions propagate in Variant Source, Variant Sink, Variant Subsystem, Variant Start, and Variant End blocks. For a complete list of blocks that support variant condition propagation, see Variant Implementation Techniques in Simulink.
Control Signal Flow with Variant Logic Using Variant Source and Variant Sink Blocks
During simulation, the Variant Source block evaluates the variant
conditions specified on its input ports and propagates these conditions to the connected
blocks. Only the input port with a variant condition that evaluates to
true becomes active, which enables the Variant Source
block to pass the corresponding input signal to the connected blocks.
Similarly, the Variant Sink block receives a single input signal and
routes it to one of several output ports, depending on which output port has a variant
condition that evaluates to true. For more information, see Propagate Variant Conditions to Define Variant Regions Using Variant Source and Variant Sink Blocks.
This diagram shows how the variant conditions V == 1 and V
== 2 defined on a Variant Source block automatically propagate
to the connected blocks so that each block is activated only when its corresponding
variant condition evaluates to true. The first and second output ports
of the Variant Source block have the variant conditions V ==
1 and V == 2, respectively. These variant conditions
propagate to the blocks connected to each port. The blocks connected to both ports display
a combined condition V == 1 || V == 2, indicating that they remain
active when either condition is met.

Apply and Propagate Variant Logic Within and Beyond Subsystems
In Variant Subsystem blocks, variant conditions are applied to each
variant choice within the block. The variant choice with a variant condition that
evaluates to true becomes active during simulation. By default, these
variant conditions do not propagate to blocks outside the Variant Subsystem
block. To enable propagation of variant condition outside the Variant
Subsystem block, select the Propagate conditions outside of variant
subsystem parameter. For more information, see Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems to Promote Consistency and Reduce Errors.
Define Start and End Boundaries of Variant Logic Propagation
To control variant condition propagation, you can define variant regions using Variant Start and Variant End blocks. These blocks allow you to specify where the variant condition propagation must begin and end, providing control over which parts of your model are affected by variant logic. For more information, see Limit Variant Condition Propagation Within Bounded Regions Using Variant Start and Variant End Blocks.
Selectively Check Signal Consistency and Include Variants in Generated Code Using Activation Time
Variant activation time determines in which phase of simulation and code generation Simulink selects the active choice for variant blocks and variant parameters. It also specifies when consistency checks across variant paths are performed, and which variant choices are analyzed when switching between the alternatives. These checks validate ports, signal dimensions, data types, sample times, and bus hierarchy to verify that switching between active and inactive variants does not introduce incompatibilities.
Variant Condition Evaluation Stages in Simulation and Code Generation
Model simulation includes the model compile and simulation loop phases. Code
generation consists of the model compile, code compile, and model startup phases. The
orange dashed markers in the figure below indicate where Simulink evaluates variant conditions to determine the active variant choice in each
phase. For example, when you set the variant activation time to update
diagram, the active variant choice is determined early during the model
compile phase in simulation.
Depending on the activation time, Simulink uses variant condition propagation to determine which blocks to compile or
execute. For example, setting the activation time to update
diagram speeds up compilation by excluding unnecessary blocks, such as
those connected to hardware or external libraries that are not used during simulation.
Similarly, setting the activation time to code compile allows
you to switch between the variant choices prior to code generation, enabling thorough
testing of multiple design alternatives.
Selecting the most appropriate activation time, helps you enhance model performance, flexibility, or reliability based on your project requirements. For more information on variant activation time, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.

How Variant Activation Time Checks Consistency and Improves Simulation Efficiency
During simulation, variant activation time determines when Simulink evaluates active and inactive variant paths for consistency. Simulink checks that each variant path has the same number of ports, compatible signal dimensions, matching data types, and other relevant properties to confirm that switching between variant choices does not introduce errors due to incompatibilities.
For example, with startup or
runtime activation time, Simulink compiles every variant path so that you can switch between them dynamically
during simulation without errors. Once this compilation is complete, fast restart enables
Simulink to reuse the compiled model for subsequent runs, provided the model
structure remains unchanged. As a result, iterative simulations, parameter sweeps, or
tests involving only input changes can run much faster since the overhead of recompiling
the model is eliminated. With update diagram activation time,
Simulink compiles only the active variant choice. Consequently, consistency checks
across all variant paths are not required, which reduces compilation overhead and results
in even faster simulation cycles for scenarios where dynamic switching is not
necessary.
This table describes the variant activation times when you perform simulation workflows for your model. For examples of when to use different types of variant activation times for various applications, see Optimal Activation of Variations During Simulation.
| Variant activation time | Evaluation stage | Simulation behavior |
|---|---|---|
update diagram | When you update the model |
|
update diagram analyze all choices | During mode update with analysis |
|
startup | At model initialization |
|
runtime | During simulation |
|
Note
When the Variant activation time parameter of a variant block
is set to update diagram, no compiled information is
available for its inactive variant choices. Any commands used to extract the compiled
information from these inactive blocks return empty results. In contrast, for any
activation time other than update diagram, compiled
information for active and inactive variant choices is available and can be retrieved
using the commands described in Programmatically Specify Block Parameters and Properties.
How Variant Activation Time Optimizes Code Generation and Run-Time Adaptability
During code generation, the variant activation time controls when the code generator
evaluates active and inactive variant paths to determine which design alternatives to
include in the generated code. For example, with the code
compile activation time, inactive variant paths are excluded during
compilation, producing a smaller and more efficient executable. With the
runtime activation time, variant choices are included in the
executable, allowing you to switch between the variant choices in real time on your
hardware.
This table describes the variant activation times to choose when you perform code generation workflows for your model. For examples of when to use different types of variant activation times for various applications, see Optimal Inclusion of Variations in Generated Code.
| Variant activation time | Evaluation stage | Simulation behavior |
|---|---|---|
code compile | During code generation | With an Embedded Coder® license, generates code for variant choices enclosed within
#if and #elif preprocessor statements.
Although all variant choices appear in the generated code, the compiler excludes
inactive paths when building the executable, resulting in a smaller code size and
improved run-time performance. |
startup | At model initialization | Generates code for variant choices enclosed within if
statements so that every variant choice is included in the executable. The active
variant choice remains fixed throughout each simulation step. This approach saves
time because you do not need to regenerate code each time you switch variant
choice on your hardware. |
runtime | During code execution | Generates code for variant choices enclosed within if
statements so that every variant choice is included in the executable. You can
change the active variant choice in real-time during execution using predefined
logic. This approach saves time because you do not need to regenerate code each
time you switch variants on your hardware. |