Main Content

addControlVariables

Add variant control variables to named variant configuration in variant configuration data object

    Description

    Note

    This function requires Variant Manager for Simulink®.

    addControlVariables(varconfigdata,nameofconfig,variantctrlvars) adds variant control variables specified by variantctrlvars to the variant configuration named nameofconfig in a Simulink.VariantConfigurationData object varconfigdata.

    example

    Examples

    collapse all

    1. Create an empty Simulink.VariantConfigurationData object.

    varconfigdata = Simulink.VariantConfigurationData
    varconfigdata = 
      VariantConfigurationData with properties:
    
                Configurations: [1×0 struct]
                   Constraints: [1×0 struct]
        PreferredConfiguration: ''
    
    

    2. Create a variant configuration and add it to the variant configuration data object.

    Define a variant control variable.

    PlantLoc = Simulink.VariantControl(Value=1,ActivationTime="code compile");

    Create a variant control variable structure.

    ctrlVarStruct = struct(Name="PlantLocation",Value=PlantLoc,Source="topdata.sldd")
    ctrlVarStruct = struct with fields:
          Name: "PlantLocation"
         Value: [1×1 Simulink.VariantControl]
        Source: "topdata.sldd"
    
    

    Add the new configuration to varconfigdata.

    addConfiguration(varconfigdata,"InternalPlantConfig", ...
     "Internal Plant Controller",ctrlVarStruct);

    3. Create a new variant control variable of type Simulink.VariantControl.

    SmartSensorMod = Simulink.VariantControl(Value=2,ActivationTime="code compile");
    newControlVarStruct = struct(Name="SmartSensorMod",Value=SmartSensorMod,Source="topdata.sldd")
    newControlVarStruct = struct with fields:
          Name: "SmartSensorMod"
         Value: [1×1 Simulink.VariantControl]
        Source: "topdata.sldd"
    
    

    4. Add the control variable to the existing variant configuration, InternalPlantConfig.

    addControlVariables(varconfigdata,"InternalPlantConfig",newControlVarStruct);

    Input Arguments

    collapse all

    Variant configuration data in which nameofconfig is defined, specified as a Simulink.VariantConfigurationData object.

    Name of the variant configuration to which the variant control variables must be added, specified as a character vector or string scalar. This configuration must be present in the variant configuration data object, varconfigdata.

    Example: "LinInterExpNoNoise"

    Data Types: char | string

    Variant control variable names and their values, specified as a structure or structure array with these fields:

    • Name — Name of the control variable, specified as a character vector or string scalar

    • Value — Value of the control variable, specified as one of these data types:

      • MATLAB® variable

      • Simulink.Parameter

      • AUTOSAR.Parameter

      • Simulink.VariantControl whose value is a MATLAB variable

      • Simulink.VariantControl whose value is a Simulink.Parameter

      • Simulink.VariantControl whose value is a user-defined type that inherits from Simulink.Parameter

      • Simulink.VariantControl whose value is a Simulink.Parameter object or an object of a class that inherits from Simulink.Parameter, with the value of the object set to a mathematical expression specified using the slexpr function.

    • Source — Data source of the control variable, specified as a character vector or string scalar.

    Example: ctrlVarStruct = struct(Name="Noise",Value="NoiseType.NoNoise",Source="plant.sldd");

    For an example that shows the use of different types of variant control variables, see Use Variant Control Variables in Variant Blocks.

    Data Types: struct

    Version History

    Introduced in R2013b