Variant Structures
With Variant Blocks in Simulink®, you can represent all design variations of a component in a single model. Each design choice is incorporated into the model as a variant choice in a single layer or a separate hierarchy. Such models have a fixed common structure and a finite set of variant choices that are activated or deactivated depending on the variant controls you select. For more information, see What Are Variants and When to Use Them. The variant activation time determines when to activate the choices and whether to include only the active choice or both active and inactive choices in the generated code. For information on activation time, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.
Topics
Generate Code
- Generate Code for Variant Subsystem Blocks
Generate code for specific implementation of component represented using Variant Subsystem block. - Generate Code for Variant Source and Variant Sink Blocks
Generate code for specific implementation of component represented using Variant Source and Variant Sink blocks. - Generate Code for Model References Connected to Variant Blocks
Reuse and incrementally load, build, and generate code for multiple variations of a component.
Interface Variant Blocks
- Conditionalize Export Function Calls in Code using Variant Blocks
Generate code for export function calls conditionally using variant blocks.
Maximize Code Reliability and Safety with Optimized Code
- Compile Code Conditionally for Variations of Component Represented Using Variant Block
Conditionally compile code for different implementations of a component using variant blocks. - Run Executables for Variant Blocks Without Recompiling Code for Changing Active Choices Using Startup Activation Time
This example explains how to generate code for multiple implementations of a component represented using a Variant Subsystem block withstartup
activation time. - Generate Code from Nested Variant Subsystem with Code Compile and Startup Activation
This example illustrates howcode compile
andstartup
variant activation time can be used together in two nested variant subsystems. - Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems to Promote Consistency and Reduce Errors
Propagate variant conditions outside a Variant Subsystem block to adapt its interface according to the state of underlying blocks. - Remove Inactive Variant Components from Generated Code at Compile Time When No Active Choices Exist
Exclude inactive variant components from generated code at compile time.
Control and Manage Variants
- Organize Variant Control Macros in Same Header File
Aggregate variant control macros into a single header file using custom storage classes. - Represent Variant Conditions of Enumerated Type in Generated Code
Represent variant control variables meaningfully in the generated code by using enumerated types. - Generate Code for Variant Elements Within Buses
Generate code for buses with elements having different variant conditions. - Use Simulink.Parameter Type of Variant Control Variables for Code Generation in Variant Blocks
If you intend to generate code for a model containing variant blocks, specify variant control variables as
objects.Simulink.Parameter