Main Content

variableNames

Names of variables in workspace

Since R2025a

    Description

    s = variableNames(w) returns the names of the variables contained in the specified workspace object.

    example

    s = variableNames(w,var1,...,varN) returns the names of the specified variables. If any of the specified variables do not exist in w, they are omitted from the output.

    example

    Examples

    collapse all

    Create a set of variables in the base workspace.

    a = 1;
    b = true;
    c = "Hello, World";

    Create a workspace object for the base workspace. Then return the variable names using the workspace object.

    w = matlab.lang.Workspace.baseWorkspace;
    s = variableNames(w)
    s = 3×1 string
        "a"
        "b"
        "c"
    
    

    Create a set of variables in the base workspace.

    a = 1;
    b = true;
    c = "Hello, World";

    Create a workspace object for the base workspace. Then return the variable names a and b.

    w = matlab.lang.Workspace.baseWorkspace;
    s = variableNames(w,"a","b")
    s = 2×1 string
        "a"
        "b"
    
    

    Input Arguments

    collapse all

    Workspace, specified as a matlab.lang.Workspace object.

    Variables, specified as string scalars or character vectors.

    Output Arguments

    collapse all

    Names of the variables, returned as a string array.

    Version History

    Introduced in R2025a