Main Content

exist

Determine whether variable exists in connected data source

Since R2024a

    Description

    varExists = exist(connectionObj,varNames) returns 1 (true) if the specified variables varNames exist in the connected data source connectionObj, 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 access multiple data sources (for example, a data dictionary and its referenced dictionaries), the function returns 1 (true) if the variable exists in any of the visible data sources.

    example

    Examples

    collapse all

    matFile = Simulink.data.connect("myMatFile.mat");
    exist(matFile,"a")
    ans = 
    
    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, string array, or cell array of character vectors.

    Version History

    Introduced in R2024a