Main Content

get

Read variables from connected data source

Since R2024a

    Description

    example

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

    If the data connection can see 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.

    Examples

    collapse all

    mw = Simulink.data.connect("myModel.slx");
    set(mw, 'b', 2);
    get(mw, '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]}

    Input Arguments

    collapse all

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

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

    Tips

    You can also read and assign values to variables by using the . operator. For example, to read a variable from a data dictionary:

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

    Version History

    Introduced in R2024a