Simulink.VariantVariable Class
R2026bNamespace: Simulink
Create variant parameter object
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 and its variant controls programmatically in the base workspace, model workspace, mask initialization code of a masked block, or in the Design Data section of a Simulink data dictionary. For workspaces and data dictionaries, you can also use 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 the
Simulink.VariantVariabledialog box.Variant 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 (Simulink 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.For variant parameters with
runtimeactivation time, you can use a Parameter Writer block or thesetVariablefunction of aSimulationobject to update theSimulink.VariantControlobject during simulation or execution of the generated code. For more information, see Change Active Choice of Variant Parameters and Variant Parameter Banks During Simulation or Execution of Generated Code.
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, mask initialization code of a masked block, 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
Boolean
Enumerated value
Simulink.Parameterobject with value of type integer, Boolean, enumeration, or a mathematical expression specified using theslexprfunctionUser-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.For variant parameters with
ActivationTimeset toruntime:Multiple
Simulink.VariantControlobjects in the condition expressions of the variant parameter choices are not supported.Using the variant parameter in a block that has the
Execution Orderset toFirstis not supported. Set the execution order toBased on priority.Export-function models are not supported.
Multirate models with the EnableMultiTasking model configuration parameter set to
"on"are not supported.
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 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.The
Simulink.VariantControlobject is created in mask initialization code and its value comes from a mask parameter, base workspace variable, or model workspace variable.
When you define
Simulink.VariantVariableobjects and its associatedSimulink.VariantControlobjects in the mask initialization code of a masked block:Specifying the variant activation time as
code compileis not supported.Simulink.VariantBankobjects are not supported.Simulink.VariantExpressionobjects are not supported.Simulink.Parameterobjects defined in mask initialization must not be used to create a variant control object or variant parameter.The value of the
Simulink.VariantControlobject must not be an expression.If a mask parameter is used to create a variant control object or variant parameter, the mask parameter must be tunable and its
Evaluateproperty must be set toon.Accelerator, Rapid Accelerator, SIL, and PIL simulation modes are not supported when a model argument passed to a referenced model is used as a mask parameter that defines a variant control, and that variant control determines a variant parameter used as a child block parameter value.
When you define
Simulink.VariantControlandSimulink.VariantVariableobjects in the model workspace:The
ActivationTimeproperty of theSimulink.VariantControlobject must be set toupdate diagram,update diagram analyze all choices,runtime, 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.
Tips
For an overview of variant parameter capabilities and supported workflows across the development lifecycle, see Components — Create Models with Parameter Value Variations.
You can manage and activate variant parameters from Variant Manager. See Manage Variant Parameters Using Variant Manager (Simulink 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 (Simulink Variant Manager)


