Contenido principal

getControlVariable

R2026b

Get variant control variable from variant configuration

Since R2026b

    Description

    ctrlVar = getControlVariable(varConfigs,ConfigurationName=configName,ControlVariableName=ctrlVarName) returns the variant control variable named ctrlVarName from the configuration configName in the Simulink.VariantConfigurations object varConfigs.

    example

    ctrlVar = getControlVariable(___,ControlVariableSource=ctrlVarSource) specifies the name of the data source where the control variable is defined, in addition to the input arguments in the previous syntax. When multiple control variables with the same name exist in different sources, use this syntax.

    example

    Examples

    collapse all

    Create a Simulink.VariantConfigurations object and add a variant configuration.

    varConfigs = Simulink.VariantConfigurations;
    varConfigs.addConfiguration("LinearBasic");

    Add a control variable to the configuration.

    varConfigs.addControlVariables("LinearBasic", ...
     struct("Name","vCtrl","Value",1,"Source","dController.sldd"));

    Get the control variable from the configuration.

    ctrlVar = getControlVariable(varConfigs, ...
     ConfigurationName="LinearBasic",ControlVariableName="vCtrl")
    ctrlVar = 
    
      struct with fields:
    
          Name: 'vCtrl'
         Value: 1
        Source: 'dController.sldd'

    When multiple control variables share the same name across different data sources, use the ControlVariableSource argument to specify which variable to retrieve.

    Create a variant configurations object and add a configuration with two control variables that have the same name but different sources.

    varConfigs = Simulink.VariantConfigurations;
    varConfigs.addConfiguration("LinearBasic");
    varConfigs.addControlVariables("LinearBasic", ...
     struct("Name","vCtrl","Value",1,"Source","dtopModel.sldd"));
    varConfigs.addControlVariables("LinearBasic", ...
     struct("Name","vCtrl","Value",2,"Source","dController.sldd"));

    Get the control variable from a specific source.

    ctrlVar = getControlVariable(varConfigs, ...
     ConfigurationName="LinearBasic",ControlVariableName="vCtrl",ControlVariableSource="dtopModel.sldd")
    ctrlVar = 
    
      struct with fields:
    
          Name: 'vCtrl'
         Value: 1
        Source: 'dtopModel.sldd'

    Input Arguments

    collapse all

    Variant configurations object that contains the configuration from which to get the control variable, specified as a Simulink.VariantConfigurations object.

    Name of the variant configuration that contains the control variable, specified as a character vector or string scalar. The configuration must be defined in varConfigs.

    Example: "LinearBasic"

    Name of the control variable to get from the variant configuration, specified as a character vector or string scalar.

    Example: "vCtrl"

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

    Example: "dController.sldd"

    Example: "base workspace"

    Output Arguments

    collapse all

    Variant control variable, returned as a structure with these fields.

    FieldTypeDescription
    Namechar

    Name of the control variable.

    Valueany MATLAB value

    Value of the control variable.

    Sourcechar

    Name of the data source where the control variable is defined.

    Version History

    Introduced in R2026b