Configure Variant Parameter Values for Instances of Referenced Models
A model reference is a reference to another model using a Model block. You can reuse a model multiple times by referring to it with multiple Model blocks. These references create a model hierarchy. You can then configure a block parameter (such as the Gain parameter of a Gain block) to use either the same value or a different value for each instance of the model. To set different values for the same parameter across multiple model instances, create and use a model argument. For more information, see Configure Instance-Specific Values for Block Parameters in a Referenced Model.
Variant parameters enable you to conditionally vary the values of block parameters in a
Simulink® model. Use the Simulink.VariantVariable class to create a variant parameter object. You create a variant parameter object in the base workspace,
model workspace, or in the Design Data section of a Simulink data dictionary. For an example, see Create a Simple Variant Parameter Model.
Define Variant Parameters in Model Workspace for Use in Referenced Models
A model workspace effectively provides a model with its own namespace, allowing you to
create variables for the model without risk of conflict with other models. When you define
variant parameters in the model workspace, set the ActivationTime property of the Simulink.VariantControl object
used as the variant control variable to update diagram,
update diagram analyze all choices, or
startup. The objects associated with the variant parameter
object, such as the Simulink.VariantControl object, the Simulink.Parameter object
used to set the Specification
property, and any Simulink.Parameter objects used as values of the variant
parameter, must be defined in the model workspace along with the parameter.
In a model reference hierarchy, you can define variant parameters with the same name but with different values scoped to the model workspaces of the referenced models.
In this example, the referenced models mModelWksRefModelA and
mModelWksRefModelB each use variant parameters K and
kv, and a variant control variable V defined in
their respective model workspaces. In mModelWksRefModelA,
V is set to 1 and in
mModelWksRefModelB, V is set to
2. The top-level model mModelWksTopModel defines
K and V in the base workspace with
V set to 3.

This image shows the results of activating the workspace variant configuration for the
model mModelWksTopModel from Variant Manager. The active choice for the
variant parameter in each model depends on the value of V in the
corresponding workspace. For information on managing variant parameters, see Manage Variant Parameters Using Variant Manager.

Specify Instance-Specific Values for Variant Parameters in a Referenced Model
To configure a variant parameter in the referenced model to use a different value for each instance of the model, configure the Simulink.VariantControl object defined in the model workspace of the referenced model as a model argument by selecting the Argument property in the Model Explorer. In each Model block that refers to this model, specify an instance-specific value for the variant control from the Block Parameters dialog box.
Open the model slexVariantParameterMultiInstance and the referenced model slexVariantParameterWiper.
open_system("slexVariantParameterMultiInstance"); open_system("slexVariantParameterWiper");


The top-level model
slexVariantParameterMultiInstanceuses the referenced modelslexVariantParameterWiperto implement a system that takes the speed of a car wiper motor as the input and computes the sweep time and sweep area parameters of the wiper. The model is configured to automatically switch between two input sources for simulation and code generation workflows: a Step block for simulation and the driver-provided wiper setting from the car for code generation. To achieve this, the model uses two Variant Source blocks with the Variant control mode parameter set tosim codegen switching. The step signal is connected to thesiminput of the Variant Source block, and the driver-provided setting is connected to thecodegeninput.
The top-level model computes the
SweepTimeandSweepAreaparameters for the front driver, front passenger, and rear wipers of the car by providing the corresponding wiper motor speed as input to three instances of theslexVariantParameterWipermodel.
The
slexVariantParameterWipermodel takes the motor speed as input and uses three variant parametersGearRatio,SweepAngle, andWiperLengthdefined in the model workspace to calculate the value of the required output parameters. These variant parameters take a different value for each of the driver, passenger, and rear wiper positions. The variant parameters use aSimulink.VariantControlobject namedWiperto specify the variant conditions for the choices. TheWipervalue can be set toWiperPosition.FRONT_DRIVER,WiperPosition.FRONT_PASSENGER, orWiperPosition.REARdefined in theWiperPosition.mfile. TheActivationTimeproperty ofWiperis set tostartupand is specified as a model argument.

In the top-level model, for each instance of the
slexVariantParameterWipermodel, the model argumentWiperis set to an instance-specific value corresponding to the wiper position. During simulation, the active choice of variant parameters in the referenced model vary for each instance based on the value ofWiperset from the top-level model. This image shows the instance value specified forWiperin the Block Parameters dialog box of the Model blockFront Driver Wiper.

Simulate the model. Open the Simulation Data Inspector and compare the logged signals to see how the output varies for different instances of the same referenced model.

See Also
Simulink.VariantVariable | Simulink.VariantControl
Topics
- Model Workspaces
- Use Variant Parameters to Reuse Block Parameters with Different Values
- Generate Code for Instance-Specific Variation of Variant Parameter Values in Model Reference Hierarchy (Simulink Coder)
- Configure Code Generation for Variant Parameters in Model Workspace Using Code Mappings Editor (Simulink Coder)