Skip to Main Content Skip to Search
Product Documentation

About Variant Objects

What Is a Variant Object?

A variant object is an instance of the Simulink.Variant class in the base workspace. You can use the controls in the variant blocks to create variant objects. Alternatively, you can create variant objects in the Model Explorer or at the command line.

The variant object can have any unique legal name. The value of the variant object specifies a variant condition.

Each variant object corresponds to a different simulation environment. When compiling the model, Simulink tests the variant condition specified by each variant object. The variant object whose variant condition is true designates the active variant. The active variant determines which variant is used during simulation. You must organize the variant objects for a model variant or a variant subsystem so that, when the model compiles, only one variant condition is true based on the current base workspace values.

Creating Variant Objects

There are three techniques for defining variant objects for your applications. Choose the technique that complements your workflow.

Reusing Variant Objects

For simplicity, the example models, AutoMRVar and AutoSSVar, show only one variant block. A variant block refers to a Model Variants block or a Variant Subsystem block. Your applications may use multiple variant blocks.

Some applications have multiple variant blocks that might reuse some of the same variant objects associated with their variants (referenced models or subsystems). For example, a model or subsystem of an automobile might include many capabilities that change depending on the applicable fuel and emission standards. To meet those different requirements using variants, you can use the same variant object in multiple variant blocks. To do this, associate the variant object with the same, or a different, variant in each of the variant blocks. The variant blocks change their selected variants in synchrony as variant control variable values change. The separate uses of the variant object do not affect one another.

Other applications might associate multiple variant objects to one variant in a Model Variants block. To do this, you can assign each of the variant objects to a different parameterization or execution mode of the referenced model variant. The separate uses of the referenced model do not affect one another.

Reusing variant objects, subsystems, and referenced models allows you to globally reconfigure a model hierarchy to suit different environments by doing nothing more than changing variant control variable values. No matter how many simulation environments you define, selecting an environment requires only setting variable or parameter values appropriately in the base workspace.

Variant Condition

A variant condition is the value of the variant object. Specify a Boolean expression that references at least one base workspace variable or parameter. The expression can include:

For instructions on specifying variant conditions, see Configuring the Model Variants Block and Configuring the Variant Subsystem Block.

For instructions on variant control variables, see Setting Up Variant Control.

  


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