Main Content

addControlVariables

Class: Simulink.VariantConfigurationData
Namespace: Simulink

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

Description

Note

This method requires Variant Manager for Simulink®.

vcdataObj.addControlVariables(nameOfConfiguration,variantControlVars) adds variant control variables to the specified variant configuration in vcdataObj, which is an object of the Simulink.VariantConfigurationData class.

example

Input Arguments

expand all

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

Example: "LinInterExpNoNoise"

Data Types: char | string

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

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

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

    • Normal MATLAB® variable

    • Simulink.Parameter

    • AUTOSAR.Parameter

    • Simulink.VariantControl with value as normal MATLAB variable

    • Simulink.VariantControl with value as Simulink.Parameter

    • Simulink.VariantControl with value as a user-defined type that inherits from Simulink.Parameter

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

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

Examples

expand all

This example shows how to add new variant control variables to an existing variant configuration in a variant configuration data object.

Create an empty Simulink.VariantConfigurationData object.

vardataObj = Simulink.VariantConfigurationData
vardataObj = 
  VariantConfigurationData with properties:

            Configurations: [1x0 struct]
               Constraints: [1x0 struct]
    PreferredConfiguration: ''

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 = 'PlantLoc', Value = PlantLoc, Source = 'topdata.sldd')
ctrlVarStruct = struct with fields:
      Name: 'PlantLoc'
     Value: [1x1 Simulink.VariantControl]
    Source: 'topdata.sldd'

% Add a variant configuration to vardataObj 
vardataObj.addConfiguration('LinInterExpNoNoise', 'Linear Internal Experimental Plant Controller', ctrlVarStruct)

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

% Create a new variant control variable
SmartSensorMod = Simulink.VariantControl('Value', 2, 'ActivationTime', 'code compile');
newControlVarStruct = struct(Name = 'SmartSensorMod', Value = SmartSensorMod, Source = 'topdata.sldd')
newControlVarStruct = struct with fields:
      Name: 'SmartSensorMod'
     Value: [1x1 Simulink.VariantControl]
    Source: 'topdata.sldd'

Add the control variable to the existing variant configuration, LinInterExpNoNoise.

vardataObj.addControlVariables('LinInterExpNoNoise', newControlVarStruct);

Version History

Introduced in R2013b