|On this page…|
A variant is each implementation of a model representing its different aspects. A variant differs in some selections from other, similar models. Using variants, you can specify multiple configurations in a single, unified block diagram. Prior to model simulation, you can switch programmatically between variants.
For example, suppose a design engineer has a model that simulates an automobile. Different models of an automobile can have many similarities but differ in terms of fuel usage, engine size, or emission standards. Each implementation of the model representing a specific automobile model is a variant. Use variants to:
Represent a single model with different configurations.
Programmatically select one active variant from multiple choices.
Select one variant from available choices, irrespective of the variant control (override variants) which determines which variant is active.
Optionally, generate code using Simulink® Coder™ with preprocessor conditionals (#if, #elif, #endif) to enable selection of the active variant at compile time.
The variant control determines which variant is active. It can be a Boolean condition expression or a Simulink.Variant object specifying the condition expression. During model compilation, Simulink evaluates the variant control to true or false. The active variant is the one for which variant control evaluates to true.
To add variants to models, Simulink provides the following blocks:
Create the subsystems or referenced models that you want to use as variants.
Depending on your application, use the Model Variants block or the Variant Subsystem block.
Define a variant control for each variant. The active variant is the variant control that evaluates to true during model compilation.
Simulate using the active variant.
Modify the variant control to select another variant and simulate again.
For variants defined in the base workspace, save the control variables to a MAT-file. See Exporting Workspace Variables.