主要内容

addControlVariables

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

    Description

    Add-On Required: This feature requires the Variant Manager for Simulink add-on.

    addControlVariables(varConfigData,ConfigurationName=nameOfConfig,ControlVariables=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,ConfigurationName="InternalPlantConfig", ...
     Description="Internal Plant Controller",ControlVariables=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,ConfigurationName="InternalPlantConfig",ControlVariables=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

    Control variables in variant configuration, 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:

    • 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

    expand all