Main Content

addChoice

Add choices to variant parameter object

    Description

    example

    P = addChoice(P,Choices{Condition,Value}) adds a new variant choice to the variant parameter object P. A variant choice consists of a variant condition and a value specified as Condition 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

    collapse all

    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

    collapse all

    Variant parameter object created using Simulink.VariantVariable, 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 to true, 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 Variant Controls in Variant Parameters.

    Example: {'V==2',5}

    Data Types: struct

    Introduced in R2021a