Main Content

hasVariables

Check if variables exist in data source workspace

Since R2022b

    Description

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

    example

    Examples

    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
    retVal = 
        true

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

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

    Input Arguments

    collapse all

    Data source workspace, specified as a Simulink.data.DataSourceWorkspace 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