Main Content

exist

Determine whether variable exists in connected data source

Since R2024a

    Description

    example

    varExists = exist(connectionObj, varNames) returns 1 (true) if the specified variable names exist in the connected data source, and 0 (false) otherwise. If varNames is an array, the output varExists is an array of the same size as varNames, and varExists(i) indicates whether the variable name varNames(i) exists in the connected data source.

    If a data connection can see multiple data sources (for example, a data dictionary and its referenced dictionaries), the function returns true if the variable exists in any of the visible data sources.

    Examples

    collapse all

    dd = Simulink.data.connect('myDictionary.sldd');
    exist(dd, 'a')
    logical
        1
    dd = Simulink.data.connect('myDictionary.sldd');
    dd.a = 1;
    dd.c = 3;
    exist(dd, ["a" "b" "c"])
    
    ans = 
    
      1×3 logical array
    
       1   0   1
    

    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.

    Version History

    Introduced in R2024a