Simulink.VariantVariable Class
Namespace: Simulink
Description
Use the Simulink.VariantVariable class to create a variant parameter
object. Variant parameter objects enable you to vary the values of block parameters in a
Simulink® model conditionally. For an overview of variant parameters, see Use Variant Parameters to Reuse Block Parameters with Different Values.
You can specify multiple values for a variant parameter object and also set properties
such as data type and dimensions applicable to all the choice values. Each value of the
variant parameter object is associated with a variant condition expression. After creating the
object, use it to set the value of block parameters in a model, such as the
Gain parameter of a Gain block. During simulation, the
value associated with the variant condition that evaluates to true becomes
the active value for that parameter. The values associated with the conditions that evaluate
to false become inactive.
Before you create a new Simulink.VariantVariable object, create a Simulink.VariantControl object representing the variant control variable to be used
in the Simulink.VariantVariable object. Use these variant control variables to
specify the variant condition expression associated with each choice value of a variant
parameter, for example, 'V == 1' where V is a
Simulink.VariantControl object. The Simulink.VariantControl
object allows you to specify an ActivationTime
for the variant parameter and a Value that is
used to evaluate the variant conditions and determine the active choice of the variant
parameter. For examples on usage of each type of variant control value, see Use Variant Control Variables in Variant Parameters.
Note
You create a variant parameter object in the base workspace, model workspace, or in the Design Data section of a Simulink data dictionary. You can add
Simulink.VariantVariableandSimulink.VariantControlobjects to these storage locations either programmatically or from the Add menu in the Model Explorer. To edit a variant parameter object, double-click the object from the workspace or data dictionary to open theSimulink.VariantVariabledialog box.To use the model workspace as the storage location:
The
ActivationTimeproperty of theSimulink.VariantControlobject used as the variant control variable for the variant parameter must be set toupdate diagram,update diagram analyze all choices, orstartup.The objects associated with the variant parameter object such as the
Simulink.VariantControlobject, theSimulink.Parameterobject used to set theSpecificationproperty, and anySimulink.Parameterobjects used as values of the variant parameter must be defined in the model workspace along with the parameter.
Variant Conditions Legend does not display the variant conditions for variant parameters. Use the Variant Parameters tab in the Variant Manager window to view and manage the variant parameters present in the workspaces associated with the model. See Manage Variant Parameters Using Variant Manager.
For variant parameters with
startupactivation time, you can use a Parameter Writer block to initialize the associatedSimulink.VariantControlobject. For an example, see Initialize Variant Control Value of Variant Parameter Using Parameter Writer Block.
Creation
creates an empty
variant parameter object.P = Simulink.VariantVariable
creates a variant parameter object and sets Properties
using one or more name-value arguments. Use this syntax to specify multiple values for the
object and to associate each value with a variant condition expression. You can also specify
other properties of the object such as data type, storage class, and dimension.P = Simulink.VariantVariable(PropertyName=Value)
Properties
Methods
Examples
Limitations
Variant parameters can only be defined in a base workspace, model workspace, or a data dictionary.
Only the values of the variant parameters change based on the variant condition that evaluates to
true. Other properties, such as storage class, data types, and so forth, remain the same irrespective of the variant condition.Variant parameters that are part of a variant parameter bank do not support AUTOSAR code generation.
The
Valueproperty of the variant control variable (Simulink.VariantControl), which determines the active value of a variant parameter, must be one of these types:Integer
Enumerated value
Simulink.Parameterobject with value of type integer, enumeration, or a mathematical expression specified using theslexprfunction.User-defined type that inherits from
Simulink.Parameter
Using the
slexprfunction or aSimulink.data.Expressionobject directly to specify a mathematical expression for the value of a choice of a variant parameter or the variant control used by the variant parameter is not supported. Instead, define the value of the variant parameter or the variant control by using aSimulink.Parameterobject with its value set to the mathematical expression by using theslexprfunction.Using a Parameter Writer block to modify the value of the
Simulink.VariantControlobject used in aSimulink.VariantVariableobject is not supported in these scenarios:The
Simulink.VariantControlvalue is modified in multiple Initialize Function blocks.The condition expression of a
Simulink.VariantVariableobject contains multipleSimulink.VariantControlobjects.The
Simulink.VariantVariableobject is part of a variant parameter bank (Simulink.VariantBank).The Parameter Writer block is connected to a block that uses a
Simulink.VariantVariableobject. In this case, the Parameter Writer block supports only changing block parameter values.The
Simulink.VariantControlobject is configured as a model argument.The model is simulated in accelerator or rapid accelerator mode when the
Simulink.VariantControlobject is defined in the model workspace.The Parameter Writer block is used to modify the value of a
Simulink.Parameterobject that is used as the value of aSimulink.VariantVariablechoice.The
Simulink.VariantVariableobject is used in an expression that contains multiple variables, for example,K + AwhereKis aSimulink.VariantVariableobject andAis a MATLAB variable.
Tips
You can manage and activate variant parameters from Variant Manager. See Manage Variant Parameters Using Variant Manager.
Extended Capabilities
Version History
Introduced in R2021aSee Also
Simulink.VariantBank | Simulink.VariantBankCoderInfo | Simulink.VariantControl
Topics
- Create a Simple Variant Parameter Model
- Change Active Values and Activation Time of Variant Parameters
- Variant Control Mode in Variant Parameters
- Use Variant Control Variables in Variant Parameters
- Options to Represent Variant Parameters in Generated Code (Embedded Coder)
- Manage Variant Parameters Using Variant Manager


