addChoice - Add choices to variant parameter object - MATLAB (original) (raw)
Main Content
Add choices to variant parameter object
Since R2021a
Syntax
Description
P = addChoice([P](#mw%5F3d0648d8-231f-4c37-98bb-de85707e816b),Choices{[Condition,Value](#mw%5F3abd066e-c1f9-4352-884a-bd9c1e1fdb65)})
adds a new variant choice to the variant parameter object P
. A variant choice consists of a variant condition and a value specified asCondition
and Value
, respectively. You can add multiple choices to p
by specifying condition-value pairs in a cell array. No two values of a variant variable can be associated with the same variant condition.
Note
Adding a value to an existing variant condition results in an error.
Examples
Create a Simulink.VariantVariable
object.
P = Simulink.VariantVariable;
Add a variant choice to the object.
P = addChoice(P, {'V==1', 3.5});
Create a Simulink.VariantVariable
object.
P = Simulink.VariantVariable;
Add multiple variant choices to the object.
P = addChoice(P, {'V==1', 3.5, 'V==2', 8.3});
Input Arguments
Variant parameter object created using [Simulink.VariantVariable](simulink.variantvariable-class.html)
, specified as a Simulink.VariantVariable
object. The choices that you specify using addChoice
are added to this object.
Variant condition and associated value, specified as a cell array. A variant condition is a control expression that determines the active value of the variant parameter object. During simulation, when a variant condition evaluates totrue
, the value associated with the condition becomes active. When a variant condition evaluates to false
, the value associated the condition becomes inactive. You can add multiple values of the object by specifying condition-value pairs in a cell array.
You can specify the variant condition as boolean MATLABĀ® expressions that contain one or more operands and operators. See Types of Variant Control Variables (Operands) in Variant Parameters and Types of Operators in Variant Parameters.
You can specify values of numeric, enumerated, orSimulink.Parameter
type. See, Numeric Variant Control Values for Rapid Prototyping of Variant Parameters, Improve Code Readability of Variant Parameters Using Enumerated Types, and Reuse Variant Parameter Values from Handwritten Code Using Simulink.Parameter Variables (Simulink Coder).
Example: {'V==2',5}
Data Types: struct
Version History
Introduced in R2021a