Set up Model Variants Using a Model Block


For new models, use a Variant Model or Variant Subsystem block instead of a Model block to contain model variants, unless you need to use variants that are conditionally executed models (models with control ports). Support for using a Model block to contain model variants will be removed in a future release. For an example of a model that uses a Variant Subsystem block as a container for variant models, see Model Reference Variants.

To convert a Model block that contains variant models to a Variant Subsystem block, right-click the Model block and select Subsystems & Model Reference > Convert to > Variant Subsystem. Alternatively, you can use the Simulink.VariantManager.convertToVariant function, specifying the Model block path or block handle.

Open the example AutoMRVar model.

addpath([docroot '/toolbox/simulink/ug/examples/variants/mdlref/']);

The symbol appears in the lower-left corner of the block to indicate that it uses variants. The name of the variant that was active the last time you saved the model appears on the block.

When you change the active variant, the variant block refreshes. The name changes to reflect the current active variant.

When you open the example model, the load function loads a MAT-file that populates the base workspace with the variables and objects used by the model.

The example shows the use of variants for the following cases:

  • The automobile can use a diesel or a gasoline engine.

  • Each engine must meet the European or United States (USA) emission standard.

AutoMRVar implements the automobile application using the Model block named Engine. The Engine block specifies four referenced models. Each referenced model represents one permutation of engine fuel and emission standards. The table shows the variant choices.

Model NameVariant ControlCondition (read only)
GasolUSAGUFUEL==1 && EMIS==1
GasolEuroGEFUEL==1 && EMIS==2
DieselUSADUFUEL==2 && EMIS==1
DieselEuroDEFUEL==2 && EMIS==2


You can use condition expressions directly in the Variant control field. You do not need to create Simulink.Variant objects.

Configure the Model Block

A Model block and its variants must satisfy model referencing requirements and limitations.. For information on requirements and limitations that apply to code generation see Represent Subsystem and Model Variants in Generated Code (Embedded Coder).

To configure a Model block and specify your variant choices:

  1. Create a model.

  2. From the Ports & Subsystems library, add a Model block to the model.

  3. Right-click the Model block and select Block Parameters (ModelReference) from the context menu.

  4. Under Variant choices, specify the model choices in the Model name column. To specify a protected model, use the extension .slxp or .mdlp. For more information, see Protected Model.


    You cannot specify a model as the default variant if that model is a variant choice in a Model block. Instead, you can add that model as a variant choice in a Subsystem block, and then specify that model as the default variant.

  5. For each model choice, specify the variant control in the Variant control column. Use a Boolean condition expression or a Simulink.Variant object representing a Boolean condition expression.

    Populate the Variant control column for each choice. You cannot comment out (%) variant control values for the Model block. However, for Variant Subsystem blocks, you can comment out variant choices.

  6. To edit the condition that determines the active variant choice, click the Create/Edit selected variant button . In the dialog box, enter the condition and click OK.

  7. If you want, specify the model arguments and the Simulation mode. All simulation modes work with model variants. For more information, see Parameterize Model Variants and Simulate Model Reference Hierarchies.

  8. If you want to add more variant choices, click the Add a new variant button .

  9. After you have specified referenced models and added variant choices, click OK.

    For next steps, see Working with Variant Choices.

Disable and Enable Model Variants

You can disable model variants without losing your variant settings. After you enable variants, they remain enabled until you explicitly disable them.

Disabling variants:

  • Hides and ignores the content of the Variant choices section of the dialog box

  • Retains the active variant as the model name

  • Ignores subsequent changes to variant control variables and other models, other than the current model

To disable variants from a Model block:

  1. Right-click the block and select Block Parameters (ModelReference) to open the block parameters dialog box.

  2. Click Disable Variants.

    To enable variants, click Enable Variants. The Model block selects an active variant according to the current base workspace variables and conditions.

Parameterize Model Variants

You can apply a parameter to a variant control. Parameter values are the same as for a referenced model.

  1. In the block parameters dialog box, under Variant choices, select the row for the variant control that you want to parameterize.

  2. In the Model argument values (for this instance) text box, specify the parameter.

  3. Click Apply.

For more information, see Model Arguments for Model Blocks That Contain Model Variants.

Log Model Variants

A Model block can log only those signals that the referenced model specifies as logged. If a model is a variant model, or contains a variant model, then you can either log all signals marked for logging or log no logged signals. The Signal Logging Selector configuration for the model must be in one of these states. For details, see Models with Model Referencing: Overriding Signal Logging Settings.

  • The Logging Mode is set to Log all signals as specified in model.

  • The Logging Mode is set to Override signals and the check box for the model block is either checked () or empty ( ). The check box cannot be filled ( ).

Additional Examples

For additional examples of model reference variants, in the Help browser, select Simulink > Examples > Modeling Features > Model Reference > Model Reference Variants.

The example sldemo_mdlref_variants shows a Variant Subsystem block that contains referenced models as variants.

Related Examples

More About

Was this topic helpful?