Skip to Main Content Skip to Search
Product Documentation

Setting Up Variant Subsystems

Variant Subsystem Block Overview

A variant subsystem provides multiple implementations of a subsystem, with only one implementation active during simulation. You can programmatically swap the active implementation with another, without modifying the model.

A Variant Subsystem block consists of multiple subsystems as follows:

The specifications of the Variant Subsystem block parameters dialog box must include:

Instructions for specifying a variant subsystem are in Configuring the Variant Subsystem Block.

Example of a Variant Subsystem Block

To view the example model, either click AutoSSVar.mdl, or execute:

addpath([docroot '/toolbox/simulink/ug/examples/variants/mdlref/']);
open('AutoSSVar.mdl');

The example model illustrates the same application as the Example of a Model Variants Block, but using variant subsystems instead of variant referenced models. Both examples show the use of variants for the following cases:

The example model, AutoSSVar, implements the application using a Variant Subsystem block, named Engine. The Engine block consists of a set of four subsystems. Each subsystem represents one permutation of engine fuel and emission standards.

Double-click the Variant Model block, Engine, to view the child subsystems.

The subsystem diagram for a Variant Subsystem block has no connections. The only blocks allowed in the Variant Subsystem block diagram are Inport, Outport, and Subsystem blocks. If you are generating code for a Variant Subsystem block, see Restrictions on Code Generation of a Variant Subsystem in the Embedded Coder documentation.

To view how to specify these variants, from the model diagram window, right-click the Engine block, and select Subsystem Parameters or select Edit > Subsystem Parameters.

View the Variant choices (list of child subsystems) table in the dialog box, as shown in the following figure.

For instructions, see Configuring the Variant Subsystem Block.

Configuring the Variant Subsystem Block

To add and configure a Variant Subsystem block to specify your variants, do the following:

  1. From the Simulink Library Browser, add a Variant Subsystem block to your model:

    Simulink > Ports and Subsystems > Variant Subsystem block

  2. To configure your variants, open the Variant Subsystem block dialog box. From the model diagram window, right-click the Variant Subsystem block, Engine, and select Subsystem Parameters or select Edit > Subsystem Parameters.

    The Variant Subsystem block parameters dialog box opens.

  3. Add a new subsystem choice in the Variant Subsystem block. In the Variant choices table, click the Create and add a new subsystem choice button . A new variant choice appears in the table and a new Subsystem block appears in the Variant Subsystem block diagram window.

  4. Rename the subsystem in the Variant Subsystem block diagram window, and open and configure the subsystem as desired. You can drag and drop existing subsystems into the new variant subsystem.

      Note  

      • The Inport, Outport, and Connection Port blocks in the Variant Subsystem block must be identical to the corresponding inports and outports of its child subsystems.

      • Inside the Variant Subsystem block diagram, you cannot create any lines connecting blocks.

  5. Return to the Variant Subsystem parameter dialog box. In the Variant object column of the Variant choices table, specify the variant name in the row of the subsystem you just configured. Double-click the default name, then type the name of the variant object. For an existing variant object, Simulink retrieves the variant condition for the object when you press Enter or click away from the Variant object. In the Variant choices table, double-click the Variant object field in the row of the subsystem you just configured. Specify the name for the Variant object.

  6. To specify the Condition that determines which variant is active, click the Create/Edit selected variant button . For the selected variant choice, you create a variant object in the base workspace if necessary, or edit an existing variant. The Simulink.Variant parameter dialog box opens.

    1. Specify the Condition for the variant object. For example, FUEL==2 && EMIS==2.

      When the variant object condition evaluates to true at compile time, the subsystem associated with the variant becomes the active variant.

    2. Click Apply to check the expression, then click OK.

    The Variant choices table is updated with the condition for the new variant object. Simulink also created the variant object as a Simulink.Variant object in the base workspace. If you use a variant control variable in the Condition expression, you must create the variant control variables in the base workspace.

  7. To add another variant, click the Create and add a new subsystem choice button

  8. Repeat the previous steps until you have specified all your variant subsystems and their associated variant objects.

    For more information on the block controls, see the Variant Subsystem block page.

  9. Click OK to close the Variant Subsystem dialog box.

For next steps, see Selecting the Active Variant. The model diagram does not display the new active variant on the block until you update the diagram.

Disabling and Enabling Subsystem Variants

You can disable individual subsystem choices. To ignore a subsystem for simulation and code generation, you can comment out the variant object in the Variant Choices table as follows:

  1. In the Variant choices table, double-click the name of the variant object.

  2. Add a '%' to the beginning of the variant object name.

  3. Click Apply and OK.

To enable the subsystem variant again, remove the %' from the variant object name.

You can also override variants and specify the active variant. See Overriding Variant Conditions.

Variant Subsystem Block Requirements

A Variant Subsystem block must meet the following requirements:

You can nest Variant Subsystem blocks to any level. The hierarchy resulting from nesting must satisfy all applicable requirements and limitations when you compile the model or generate code for it.

Variant Subsystem Demo

To see a demo that shows how to define a variant subsystem, click sldemo_variant_subsystems.mdl. In the Help Browser, select: Simulink > Demos > Modeling Features > Subsystems > Variant Subsystems.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS