Main Content

Simulink.VariantControl class

Package: Simulink

Create a variant control variable object

Description

The Simulink.VariantControl class creates a variant control variable object to associate the value of a variant control variable with a variant activation time. Use the Simulink.VariantControl object to determine the active value of variant parameter during simulation.

Creation

variantControlVariable = Simulink.VariantControl creates a variant control variable object with no value and 'ActivationTime' set to 'update diagram'.

variantControlVariable = Simulink.VariantControl(Name,Value) creates a variant control variable object as specified by Name,Value pair arguments. Using this syntax, you create an object and associate its value with a variant activation time.

Input Arguments

expand all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Value', 1, 'ActivationTime', 'update diagram'

Value of variant control variable object, specified as scalar variables and enumerated types.

Example: 'Value', 1

Activation time of active value of variant parameter, specified as 'update diagram', 'update diagram analyze all choices', or 'code compile'. This property also determines whether to include only the active value or both active and inactive values of the variant parameter in the generated code.

Set the activation time as:

  • 'update diagram' –– Simulink® sets the active values of variant parameters during update diagram before the propagation of signal attributes. Inactive choices are removed prior to propagation of signal attributes. Signal attributes such as dimension and data type are not analyzed for consistency across the model. The generated code contains only the active value of variant parameters.

  • 'update diagram analyze all choices'–– Simulink sets the active values of variant parameters during update diagram after the propagation of signal attributes. Signal attributes are propagated to both active and inactive values. Signal attributes such as dimension and data type are analyzed for consistency across the model. The generated code contains only the active value of variant parameters.

  • 'code compile' ––Simulink sets the active choice during code compile. Signal attributes are propagated to both active and inactive values. Signal attributes such as dimension and data type are analyzed for consistency across the model. The generated code contains both active and inactive values of the variant parameters. In the generated code, the values are enclosed in preprocessor conditionals #if and #elseif.

Example: 'ActivationTime', 'code compile'

Methods

expand all

Examples

collapse all

Scalar MATLAB variables allow you to rapidly prototype variant values when you are still building your model. They help you focus more on building your variant values than on developing the expressions that activate those choices.

In the MATLAB Editor, specify variant choices in their simplest form as scalar variables in a Simulink.VariantVariable object.

vpObj = Simulink.VariantVariable('Choices',{'VCtrl==1', 1000, 'VCtrl==2', 2000})
vpObj = 
VariantVariable with 2 choices:

 Condition 	Value
__________	_____
VCtrl == 1	1000
VCtrl == 2	2000

Specification: ''

Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or
remove choices

Activate one of the variant values by defining a control variable, VCtrl, and setting its value to 1 in a Simulink.VariantControl object. This condition activates the value 1000 and assigns this value to vpObj.

VCtrl = Simulink.VariantControl('Value', 1, 'ActivationTime', 'update diagram')
VCtrl = 
  VariantControl with properties:

             Value: 1
    ActivationTime: 'update diagram'

If you change the value of VCtrl to 2, Simulink® sets the value of vpObj to 2000.

VCtrl.Value = 2;

Use enumerated types to give meaningful names to integers used as variant control values.

In the MATLAB® Editor, define the classes that map enumerated values to meaningful names.

Specify the names as variant choices in a Simulink.VariantVariable object.

vpObj = Simulink.VariantVariable('Choices', {'VCtrl == EngType.Small',3.5,'VCtrl == EngType.Big',8.5})
vpObj = 
VariantVariable with 2 choices:

       Condition       	Value
______________________	_____
VCtrl == EngType.Big  	8.5000
VCtrl == EngType.Small	3.5000

Specification: ''

Use getChoice, setChoice, addChoice, removeChoice to access, modify, add or
remove choices

Activate one of the variant values by defining the control variable VCtrl and setting its value to EngType.Small in a Simulink.VariantControl object. This condition activates the value 3.5 and assigns this value to vpObj.

VCtrl = Simulink.VariantControl('Value',EngType.Small,'ActivationTime','code compile')
VCtrl = 
  VariantControl with properties:

             Value: Small
    ActivationTime: 'code compile'

Using enumerated types simplifies the generated code because it contains the names of the values rather than integers.

Introduced in R2021a