Main Content


Check if variables exist in data source workspace

Since R2022b



    varExists = hasVariables(dsWks,varNames) checks if the specified variables exist in the data source workspace represented by the object dsWks.


    collapse all

    Add some variables to a data source workspace.

    setVariable(sourceWorkspace,'b', 2);
    setVariables(sourceWorkspace,["c" "d"], {3,4});
    setVariables(sourceWorkspace,{'e','f'}, {5,6});

    Check if variable b is in the data source workspace.

    retVal = hasVariables(sourceWorkspace,'b');
    retVal = 

    Now check if the variables a and e are in the data source workspace.

    retVal = hasVariables(sourceWorkspace,["a" "e"]);
    retVal = 
        1x2 logical array
          0  1

    Input Arguments

    collapse all

    Data source workspace, specified as a object.

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

    Example: ["c" "d"]

    Example: {'e', 'f'}

    Output Arguments

    collapse all

    True or false result, returned as a logical array. Dimensions of the logical array match the dimensions of varNames.

    Version History

    Introduced in R2022b