|On this page…|
addpath([docroot '/toolbox/simulink/ug/examples/variants/mdlref/']); open('AutoMRVar');
The symbol appears in the lower-left corner of the block to indicate that it uses variants. The outline of model variant block depends on the simulation mode.
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. Its 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 American (USA) emission standard.
AutoMRVar implements the automobile application using the Model Variants block named Engine. The Engine block specifies four referenced models. Each referenced model represents one permutation of engine fuel and emission standards. The variant choices are listed in the table:
|Model Name||Variant Control||Condition (read only)|
|GasolUSA||GU||FUEL==1 && EMIS==1|
|GasolEuro||GE||FUEL==1 && EMIS==2|
|DieselUSA||DU||FUEL==2 && EMIS==1|
|DieselEuro||DE||FUEL==2 && EMIS==2|
You can configure a Model Variants block and specify your variant choices.
Open a new, empty model.
From the Simulink Library Browser, Ports & Subsystems library, add a Model Variants block to the model.
Right-click the Model Variants block and select Block Parameters (ModelReference) from the context menu.
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.
For each model choice, specify the variant control in the Variant control column. The variant control can be a Boolean condition expression or a Simulink.Variant object representing a Boolean condition expression.
You must populate the Variant control column for each choice. You cannot comment out (%) variant control values for the Model Variants block. However, for Variant Subsystem blocks, you can comment out variant choices.
To edit the condition which determines the active variant choice, click Create/Edit selected variant. In the dialog box enter the condition.
(Optional) Specify the model arguments and the Simulation mode. All simulation modes work with model variants. For more information, see Parameterize Model Variants and Referenced Model Simulation Modes.
If you want to add more variant choices, click Add a new variant.
Repeat the previous steps until you have specified all your referenced models and their associated variant controls. For more information, see Model Variants block page.
After you have added all your variant choices click OK to close the dialog box.
For next steps, see Select the Active Variant for Simulation.
You can disable model variants without losing your variant settings. After you enable variants, they remain enabled until you explicitly disable them. You can close and reopen the Model Variants block without affecting the variant specification.
To disable variants from a Model Variants block:
Right-click the block and select Block Parameters (ModelReference) to open the block parameters dialog box.
Click Disable 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.
If you decide to reenable variants later, select Enable Variants. The Model Variants block selects an active variant according to the current base workspace variables and conditions.
If you want, you can apply a parameter to a variant control. Parameter values are the same as for any referenced model. For more information, see Parameterize Model References) .
Under Variant choices select the row in the table for the variant control that you want to parameterize.
In the Model argument values (for this instance) field, specify the parameter.
Repeat these steps for each parameter that you want to parameterize.