Documentation Center

  • Trial Software
  • Product Updates

Simulink.Variant class

Package: Simulink

Specify a model reference variant and its execution environment


A Simulink.Variant object specifies a variant object, which is defined using a Boolean expression called a variant condition. For more information, see Variant Controls. A Model Variants block and a Variant Subsystem block use variant objects to associate an execution environment with each of its variants.

The variant condition references MATLAB® variables and/or Simulink® parameter objects in the base workspace called variant control variables. The variant condition must evaluate to true or false when the model is compiled.

For a given Model Variants block or Variant Subsystem block, you must define the variant objects so that only one evaluates to true. The variant object, whose variant condition evaluates to true, is the active variant for that variant block.


variant=Simulink.Variant(VariantCondition) creates a variant object in the base workspace. The object name is variant, and the associated variant condition is VariantCondition. The object can have any unique legal MATLAB name.

The VariantCondition must be a Boolean expression that references at least one base workspace variable or parameter. A variant condition can include scalar variables, enumerated values, the operators ==, ~=, &&, ||, ~, as well as parentheses for grouping. If you specify the condition literally, surround it with single quotes.

You can also create a variant object using the Model explorer. Select the Base Workspace, choose Add > Simulink.Variant, and specify the desired name and variant condition in the Contents and Dialog panes. If you specify the condition literally, do not surround it with single quotes (unlike the MATLAB API, which requires single quotes).




The Boolean expression associated with the variant object.




Create a variant object with a variant condition:

GU=Simulink.Variant('Fuel==1 && Emis==1')
Was this topic helpful?