Contenido principal

Variant Modeling Strategies for System Development with Simulink

R2026b

The V-model for system development represents a development process. The model demonstrates the relationship between each phase of the development cycle on the left side and its associated validation phase on the right side.

V-model system development life cycle diagram showing the phases where Simulink variant capabilities apply

Simulink® variants support the V-model development process by providing variant capabilities from the System Level Model phase, down to Code Generation, and up to the System Integration and Test phase. In the System Level Model and Component phases, you can use variant blocks, variant parameters, and symbolic dimensions to capture structural and data variations. The generated code contains the variations defined in the model and its components. In the test phases, you can use the Simulink Design Verifier™ to generate test cases to identify hidden design errors and use Simulink Test™ to execute user-defined tests. Also, you can use Simulink Coverage™ to get coverage for all variants.

Depending on your application and its role in the process, you might focus on particular phases of the V-model or revisit certain phases multiple times throughout the V-model lifecycle.

This topic describes strategies that you can use for plant and controller design at different phases of the V-model. For a more specific list of goals related to applying variations in your model, along with the guidance on how to achieve those goals, see V-Model for System Development with Simulink Variants.

Design Structural, Value, and Dimension Variations

Using variant blocks, you can conditionally switch between different structural alternatives within a model. With variant parameters, you can design block parameters with different values or dimensions and configure instance-specific values for referenced models. You can also use symbolic dimensions to simulate various sets of dimension choices without regenerating code for every set.

  • Model structural variations — With variant blocks such as Variant Subsystem blocks, you can encapsulate and switch between different component implementations, and with Variant Source and Variant Sink blocks, you can manage alternative signal paths. For external management, Variant Assembly Subsystem blocks allow you to add or remove variant choices without directly modifying the model structure. Additionally, Variant Start and Variant End blocks help you confine and collectively control variations within a specific set of blocks, ensuring that only intended elements are affected. For examples to configure structural variations in your model, see Implement Structural Variabilities for Components.

    When switching between these variations, variant blocks propagate changes to the affected elements within your model, eliminating the need for manual updates. For examples on these techniques, see Propagate Variant Conditions from Variant Blocks Upstream and Downstream.

    Additionally, you can control transitions between multiple design configurations within Stateflow® charts using variant transitions, and manage architectural variations in System Composer™. For AUTOSAR software components, you can enable or disable interfaces or implementations in the execution path using variation points, with AUTOSAR system constants serving as inputs to control these points. For examples, see System-Level Model, Components — Create Models with Variations in Transition Paths, and Components — Create Models with Variations in AUTOSAR Interfaces.

  • Model value variations — With variant parameters, you can design block parameters with different values or dimensions, and configure instance-specific values for referenced models. Each variant parameter defines a set of choices and associates each choice with a variant condition expression. When the conditions are evaluated, the model selects the appropriate parameter value based on the active variant, allowing you to represent multiple design alternatives without changing the model structure. For examples to configure parameter value variations, see Implement Variabilities in Parameter Values.

  • Model dimension variations — With symbolic dimensions, you can define model signals, parameters, and states using symbolic names instead of fixed numeric values. Symbolic dimensions enable you to simulate and generate code for models with varying dimensions, without needing to manually update or regenerate the model for each configuration. For examples to configure signals with symbolic dimensions, see Components — Create Models with Variations in Dimensions.

Enhance Reuse and Prevent Conflicts with Scoped Variant Controls

For variant blocks and variant parameters, each variant choice is linked to a variant control that determines which variant choice is active. Only one variant control of a variant block or a variant parameter can evaluate to true at a time. The variant blocks support expression, label, and sim codegen switching as control modes, while variant parameters support only the expression mode. Select the appropriate control mode based on your project needs. For an introduction to variant controls in variant blocks and variant parameters, see Define, Activate, and Manage Design Alternatives in Simulink Models.

You can encapsulate the variant controls in mask workspaces and model workspaces to localize the control variables to specific blocks or models and manage their visibility. Scoping the variables prevents unintended modifications from outside their intended context and enables you to reuse the same control names in different parts of your design without conflicts. Additionally, mask workspace variables enable each masked block instance to have its own set of variant control values, allowing you to configure blocks independently. Furthermore, if you want each instance of a referenced model to use different variant control values, you can use model arguments to achieve instance-specific variation. This approach supports modularity and improves model portability. For examples on variant control management techniques using workspace variables, see Control Visibility of Variant Regions.

Achieve Configurable and Maintainable Models with Variant Control Variables

A variant control variable is a workspace variable in Boolean expressions of the variant block or variant parameter when the variant control mode set to expression. The value of the variant control variable determines which Boolean expression evaluates to true to activate the corresponding variant choice. By changing the values of variant control variables, you can switch between the variant choices without altering the overall model structure. You can define these variables in various workspaces, such as the base workspace, data dictionary, mask workspace, or model workspace, to control the scope of variant selection locally or global as needed.

For an introduction to variant control variables in variant blocks, see:

To determine the appropriate type of variant control variable to use and the values to assign to them, see the flow charts in:

Simulate Varying Designs in Plant and Controller Systems

Simulation and code generation for complex models in plant modeling and controller design require design flexibility and execution efficiency.

Plant modeling involves creating a representation of a physical system to predict its behavior, whereas, controller design involves creating logic that adjusts a system’s output to achieve desired performance. For example, modeling a car's braking system to understand how it responds to different road surfaces is an example of plant modeling, while designing an anti-lock braking controller to optimize braking performance under those conditions is an example of controller design.

Features, such as variant control mode, variant activation time, and parallel execution, enable you to manage active variants, minimize simulation overhead, and ensure model consistency.

Optimal Activation of Variations During Simulation

The following table explains how the combinations of variant activation times and variant control modes help address different modeling requirements. For an introduction to variant activation times and variant control modes, see Selectively Check Signal Consistency and Include Variants in Generated Code Using Activation Time and Switch Between Variant Choices Using Variant Controls.

Control designVariant activation timeVariant control modeUse case

Plant modeling

update diagramlabel

Use this combination in applications such as aircraft autopilot modes, vehicle drive profiles, or industrial machine settings, where the desired variant is selected by name before simulation and remains unchanged throughout the simulation.

Consider a passenger aircraft system with predetermined autopilot modes. The plant model includes four variant choices:

  • ManualControl, which is active when the label Manual is selected.

  • AutopilotLevel1, which is active when the label Level1 is selected.

  • AutopilotLevel2, which is active when the label Level2 is selected.

  • AutopilotEmergency, which is active when the label Emergency is selected.

To simulate the system in the Level2 autopilot mode, suppose the label Level2 is selected.

  • With the variant activation time set to update diagram, Simulink compiles only the AutopilotLevel2 variant and ignores the others. Since the autopilot mode is set before simulation and remains unchanged, this option minimizes overhead, accelerates simulation, and optimizes memory usage.

  • With the variant control mode set to label, using descriptive labels such as Level2 makes it easy to select the correct autopilot mode without confusion.

Controller designupdate diagramexpression

Use this combination for systems such as industrial robotic arms, where the desired variant is selected by setting specific variables before simulation and these values remain unchanged throughout simulation.

Consider an industrial robotic arm system with predetermined controller configurations. The controller design includes two variant choices:

  • PrecisionController, which is active when the variant control expression OperationMode == 1 && Load < 5 evaluates to true.

  • HeavyLoadController, which is active when the variant control expression OperationMode == 2 || Load >= 5 evaluates to true.

To simulate the arm's behavior under heavy load conditions, suppose OperationMode is set to 2 and Load is set to 7.

  • With the variant control mode set to update diagram, Simulink compiles only the HeavyLoadController variant and ignores the PrecisionController variant. Since both operation mode and load are set before simulation and remain unchanged, this option minimizes overhead, accelerates simulation, and optimizes memory usage.

  • With the variant control mode set to expression the controller is selected based on the value of OperationMode and Load which requires a decision logic.

Controller designupdate diagram analyze all choicesexpression

Use this combination in applications such as automotive systems, where the variant is selected by configuring multiple variables before simulation and remains unchanged, but it is important to verify all variant logics for errors to confirm readiness for future deployment or evolving requirements.

Consider an automotive engine control unit (ECU) model that includes two sensor calibration strategies:

  • VendorA_Calibration, which is active when the variant control expression SensorVendor == 1 && Temperature < 40 evaluates to true,

  • VendorB_Calibration, which is active when the variant control expression SensorVendor == 2 || Temperature >= 40 evaluates to true.

To simulate the ECU using Vendor A’s calibration under normal temperature conditions, suppose SensorVendor is set to 1 and Temperature is set to 25.

  • With the variant activation time set to update diagram analyze all choices, Simulink analyzes both the active VendorA_Calibration and inactive VendorB_Calibration for consistency and modeling errors, but compiles only the Vendor A for simulation.

    This approach validates even the unused calibration logic for Vendor B is free of errors. If future changes in operating conditions, performance requirements, or regulations require you to switch to Vendor B’s calibration or operate at higher temperatures, you can do so as both calibration strategies are error-free and ready for deployment.

  • With the variant control mode set to expression, the controller is selected based on a combination of variables SensorVendor and Temperature, which requires decision logic.

Controller designstartupexpression

Use this combination in applications such as advanced vehicle suspension models, where you intend to compile the entire model just once and then select the desired variant before each simulation run based on the value of multiple variables. This setup is ideal for simulation environments that require Fast Restart-based workflows, rapid prototyping, and integrated test and verification environments such as Simulink Test scenarios that override parameters, and Simulink Design Verifier and Simulink Verification and Validation™ workflows that require coverage across all variant paths where maintaining a single precompiled artifact can accelerate the testing cycle. For more information, see Run Iterative Simulations Without Recompiling Model for Variant Systems Using Fast Restart and Simulate Variant Blocks in Accelerator and Rapid Accelerator Modes with Startup Activation Time.

Consider an advanced vehicle suspension system model that includes two controller designs:

  • ComfortController, which is active when the variant control expression RoadType == 1 && VehicleSpeed < 60 evaluates to true.

  • SportController, which is active when the variant control expression RoadType == 2 || VehicleSpeed >= 60 evaluates to true.

To simulate the system for highway driving, suppose RoadType is set to 2 and VehicleSpeed is set to 100.

  • With the variant activation time set to startup, Simulink analyzes both ComfortController and SportController for consistency and compiles both controller designs. Although both controllers are compiled, only SportController is executed when simulating highway driving. If you later change driving conditions, for example, switching to city driving with RoadType == 1 and VehicleSpeed < 60, Simulink can switch to ComfortController without requiring a full model rebuild or introducing unforeseen errors, minimizing delays.

    Additionally, if you enable accelerator or rapid-accelerator modes with Fast Restart, you can quickly rerun simulations after changing driving conditions such as switching between highway and city scenarios without recompiling the entire suspension system model. This setting significantly speeds up testing and validation, especially when your suspension system is part of a large, modular model that uses model references.

  • With the variant control mode set to expression, the controller is selected based on a combination of variables RoadType and VehicleSpeed, which requires decision logic.

Controller designruntimeexpression

Use this combination in applications such as aircraft flight control systems, where the decision about which variant to execute depends on dynamic simulation-time inputs rather than the predetermined conditions. This setup enables transitions between control strategies during simulation, allowing the system to adapt in real time to changing atmospheric conditions without stopping or recompiling the model. For more information, see Control Active Choice of Variant Subsystem During Simulation or Execution of Generated Code.

Consider an aircraft flight control system model that includes two altitude control strategies:

  • CruiseAltitudeController, which is active when the variant control expression FlightPhase == 2 && TurbulenceLevel < 3 evaluates to true.

  • TurbulenceAltitudeController, which is active when the variant control expression FlightPhase == 2 && TurbulenceLevel >= 3 evaluates to true.

To simulate the system for cruise flight in mild conditions, suppose FlightPhase is set to 2 and TurbulenceLevel is set to 1.

  • With the variant activation time set to startup, Simulink analyzes both CruiseAltitudeController and TurbulenceAltitudeController for consistency and executes both controller designs. This option allows the flight control system to transition between altitude control strategies, for example, switching from CruiseAltitudeController to TurbulenceAltitudeController if the aircraft suddenly encounters increased turbulence during cruise. As a result, the system can adapt to changing flight conditions without stopping or restarting the simulation.

  • With the variant control mode set to expression, the controller is selected based on a combination of variables FlightPhase and TurbulenceLevel, which requires decision logic.

Controller designupdate diagram or update diagram analyze all choicessim codegen switching

Use this combination in applications such as smart home lighting systems to automatically switch between simulation and code generation controllers without manually configuring the model based on whether you are running simulations to test algorithms or generating code for embedded deployment.

Consider a smart home lighting system model that includes two controller designs:

  • SimController, a floating-point controller for simulating lighting features in a virtual environment.

  • CodegenController, a fixed-point controller for deployment on embedded lighting hardware.

In this example,

  • With the variant control mode set to sim codegen switching, Simulink automatically selects the appropriate controller depending on whether you are simulating the model or generating code. No manual changes to variables or settings are needed.

  • With the variant activation time set to update diagram, Simulink switches between the controllers before starting simulation or code generation, compiling only the relevant controller for optimal performance.

  • If update diagram analyze all choices is selected as the variant activation time, Simulink additionally checks both controllers for consistency and reports an error each time you simulate the model. Both controllers remain error-free and ready for use, even if you are only working with one controller at a time.

For examples to control which variations to analyze using variant activation times, see Control Variant Activation Times of Structurally Varying Systems and Control Variant Activation Times of Varying Parameter Values.

Parallel Simulation of Variations

In Simulink, the parsim command enables you to perform parallel simulations across available processors or clusters for different variant choices. By using a Simulink.SimulationInput object, you can define multiple variant configurations and run them in parallel, reducing simulation time. For more information, see Simulate Variant Subsystem with Startup Activation Using parsim.

Independent Execution of Variations with Simulink Compiler

With startup variants, you can use Simulink Compiler™ to create a standalone executable that runs simulations independently of the Simulink environment. For more information, see Create Standalone Executables with Variants Using Simulink Compiler.

Generate Code to Conditionally Include Variants

You can include design variations in generated code to reuse and configure the code for different stages of development, such as testing different implementations or providing multifunctional code to third parties. The code can be generated to accommodate structural, value, and dimensional variations, as well as different transition paths, ensuring the code remains adaptable to a wide range of requirements and use cases. For an introduction to code generation with variants, see Variant Systems (Simulink Coder).

  • Generate Code for Structurally Varying and Value-Varying Systems — You can generate code or executables that include both active and inactive variants of variant blocks or variant parameters, enabling you to switch between different system configurations either before code compilation or at model startup. This approach optimizes performance by including only the relevant portions of the model in the executable and, with activation times such as startup, allows for the flexible selection of configurations at execution without needing to regenerate code. For links to example models, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

  • Generate Code for Varying Dimensions — Using symbolic dimensions enable you to define model signals, parameters, and states with symbolic names rather than fixed numeric values. By representing dimensions as symbols, the model can automatically adjust the sizes of signals, parameters, or ports to meet different requirements, eliminating the need for manual updates. As a result, the generated code remains flexible and easily adapts to a variety of system configurations. For examples of how to generate code for models with symbolic dimensions, see Generate Code for Varying Dimensions.

  • Generate Code for Varying Transition Paths — You can use variant transitions to create Stateflow charts in Simulink models that generate code adaptable to a wide range of software scenarios. Variant transitions enable you to represent multiple variations within a single Stateflow chart so that you select the appropriate behavior during code generation or compilation. For examples of how to generate code for Stateflow charts with variant transitions, see Generate Code for Varying Transition Paths.

Organize and Represent Variant Controls to Improve Code Quality

You can improve how variant controls are organized and represented in generated code.

  • Use Simulink.Parameter objects in variant controls to control how these variables are represented in the generated code. For example, you can specify whether the variables appear in header or source files, and configure their definition and declaration scope to enable global access or restrict them to file-level visibility.

  • Use enumerated types to enhance code readability by assigning meaningful names to values instead of integers.

  • Group variant parameters with the same variant conditions into variant parameter banks to switch between parameter sets.

  • Use Code Mappings Editor — C (Simulink Coder) to set instance-specific parameter values.

For examples of how to organize and represent variant controls for better code quality, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

Optimal Inclusion of Variations in Generated Code

Code generation for complex models in controller design requires both design flexibility and execution efficiency. Features such as Variant activation time and Variant control mode allow you to specify which design variations are included in the generated code and at what stage the selection is made either before code generation, at model initialization, or during code execution. The following table shows how different combinations of variant activation times and variant control modes help address different modeling requirements. For an introduction to variant activation times and variant control modes, see Selectively Check Signal Consistency and Include Variants in Generated Code Using Activation Time and Switch Between Variant Choices Using Variant Controls.

Use caseVariant activation timeVariant control modeExample
Controller designcode compileexpression

Use this combination in applications where multiple control strategies must be thoroughly validated during development, while optimizing resource usage in the production system by including only the necessary logic.

Consider an automotive braking system model that includes two braking control strategies:

  • StandardController, which is active when the variant control expression VehicleVariant == 1 evaluates to true.

  • ABSController, which is active when the variant control expression VehicleVariant == 2

By setting the variant activation time to code compile, the generated code includes both the Standard and ABS controllers. This configuration provides several advantages:

  • Thorough validation — You can test, review, and certify all possible braking strategy, which is essential for meeting safety standards and regulatory requirements, even if only one controller is active in the final production build.

  • Optimized production code — When creating the final production executable for a specific vehicle variant, only the relevant controller is included in the compiled binary.

  • Efficient resource usage — This approach optimizes memory usage and reduces code size as the embedded hardware contains only the necessary controller logic.

Controller designstartupexpression

Use this combination in applications where multiple control strategies must be thoroughly validated during development, while retaining the flexibility to activate the appropriate variant at system startup, without requiring recompilation.

Consider a network router firmware that includes two firewall strategies:

  • StandardFirewall, which is active when the variant control expression SecurityLevel == 1 evaluates to true.

  • AdvancedFirewall, which is active when the variant control expression SecurityLevel == 2 evaluates to true.

By setting the variant activation time to startup, the generated code includes both firewall controllers. This configuration provides several advantages:

  • Thorough validation — You can test, review, and certify all possible security strategies during development for robust protection, even though only one firewall strategy is selected and activated at the system startup.

  • Run-time adaptability — Both strategies remain present in the compiled code, enabling the device to switch its active firewall based on the selected security level at boot without recompiling the code.

Controller designruntimeexpression

Use this combination in applications that require switching between variant choices while the generated code is running, such as adaptive systems and real-time testing scenarios.

Consider an autonomous drone navigation system that includes two path-planning algorithms:

  • UrbanNavigator, which is active when the variant control expression EnvironmentType == 1 evaluate to true.

  • ForestNavigator, which is active when the variant control expression EnvironmentType == 2 evaluates to true.

By setting the variant activation time to runtime, the generated code includes both navigation algorithms. This configuration offers several advantages:

  • Thorough validation — You can test, review, and certify all possible navigation strategies during development.

  • Real-time adaptability — During operation, the drone can seamlessly switch between algorithms as it transitions between urban and forest environments without stopping or restarting the system.

For examples on controlling which variations to include in the generated code using variant activation times, see Generate Code for Structurally Varying Systems and Generate Code for Varying Parameter Values.

Deploy Variant Models for Different Targets

With variant blocks, you can configure the models to deploy on different target platforms:

Systematic Verification and Validation of Variations Through Tests

You can identify hidden design errors and detect model constructs within variants that may result in integer overflow, dead logic, array access violations, and division by zero by generating test cases using Simulink Design Verifier. Additionally, you can execute user-defined tests on both active and inactive variants in a model by using Simulink Test. If your model has variant configurations defined using Simulink Variant Manager™, you can use the configurations to run tests programmatically for variant paths in the model. For examples of how to perform and automate testing across different variant configurations, see Component Tests and System-Level Tests.