主要内容

get

Read variables from connected data source

Since R2024a

    Description

    get(connectionObj,varNames) returns the values of the specified variables varNames in the connected data source connectionObj. The function returns a missing value, displayed as <missing>, for variables that are not defined in the connected data source connectionObj.

    If the data connection can access multiple definitions of the same variable (for example, in a data dictionary and in a referenced dictionary), the function reports an error if the definitions of the variable are inconsistent. For multiple consistent definitions, the function returns the value of one of the variable definitions.

    example

    Examples

    collapse all

    matFile = Simulink.data.connect("myMatFile.mat");
    set(matFile,"b",2);
    get(matFile,"b")
    ans = 
    
        2
    mw = Simulink.data.connect("myModel.slx")
    set(mw,{'e','f'},{5,6});
    get(mw,{'e','x','f'})
    ans = 
    
    1x3 cell array
    
        {[5]}    {[<missing>]}    {[6]}

    Create a connection to a parent data dictionary and read variables from its referenced dictionaries.

    Open the example model sldemo_fuelsys_dd. The model has an attached data dictionary sldemo_fuelsys_dd with referenced dictionaries sldemo_fuelsys_dd_controller and sldemo_fuelsys_dd_plant.

    openExample('simulink_automotive/UseDDForFuelContSysExample','supportingfile','sldemo_fuelsys_dd')
    

    Create a connection to the parent data dictionary.

    dd = Simulink.data.connect("sldemo_fuelsys_dd.sldd");
    

    Get the value of a parameters contained in the referenced dictionary sldemo_fuelsys_dd_plant.

    get(dd,"Patm")    % Variable contained in dictionary sldemo_fuelsys_dd_plant
    
    ans = 
    
      Parameter with properties:
    
              Value: 1
         Complexity: 'real'
         Dimensions: [1 1]
          CoderInfo: [1×1 Simulink.CoderInfo]
        Description: ''
           DataType: 'auto'
                Min: []
                Max: []
               Unit: 'bar'

    Get the value of a parameters contained in the referenced dictionary sldemo_fuelsys_dd_controller.

    get(dd,"max_speed")    % Variable contained in dictionary sldemo_fuelsys_dd_controller
    
    ans = 
    
      Parameter with properties:
    
              Value: 628
         Complexity: 'real'
         Dimensions: [1 1]
          CoderInfo: [1×1 Simulink.CoderInfo]
        Description: ''
           DataType: 'auto'
                Min: []
                Max: []
               Unit: 'rad/s'

    Input Arguments

    collapse all

    Connection to data source, specified as a Simulink.data.DataConnection object.

    Variable names, specified by a string, character vector, string array, or cell array of character vectors.

    Tips

    You can also read and assign values to variables by using dot notation. For example:

    dd = Simulink.data.connect('myDictionary.sldd');
    dd.x = 1;
    dd.x
    
    ans = 
    
         1
    
    dd.b
    
    ans = 
    
      missing
    
        <missing>
    

    Version History

    Introduced in R2024a