Main Content

who

List variables in workspace

Description

example

who lists in alphabetical order the names of all variables in the currently active workspace.

example

who -file filename lists the variable names in the specified MAT-file.

who global lists the variable names in the global workspace.

example

who ___ var1 ... varN lists only the specified variables. Use this syntax with any of the arguments in the previous syntaxes.

example

who ___ -regexp expr1 ... exprN lists only the variables that match the specified regular expressions.

example

C = who(___) stores the names of the variables in the cell array C.

Note

You must use the functional form of who when there is an output argument.

Examples

collapse all

List the names of variables in the current workspace that start with the letter a.

who a*

Display the names of variables in the current workspace that end with ion.

who -regexp ion$

List the names of variables stored in the sample MAT-file durer.mat.

who -file durer.mat
Your variables are:

X        caption  map      

Store the list of variable names in durer.mat in cell array C.

C = who('-file','durer.mat');

Display the contents of C.

for k=1:length(C)
   disp(C{k})
end
X
caption
map

List all the variable names in the current workspace while paused in a nested function.

Create a file who_demo.m, that contains these statements.

function who_demo
date_time = datestr(now,'dd-mmm-yyyy');
 
date_time_array = strsplit(date_time,{'-',''});
get_date(date_time_array);

   function get_date(d)
      day = d{1};  %#ok<*NASGU>
      mon = d{2}; 
      year = d{3}; 
      keyboard
   end

end
K>> 

Run who_demo. MATLAB® pauses at the line with the keyboard command.

who_demo

Call the who function. MATLAB displays the names of the variables in the nested get_date function and in all functions containing the nested function.

K>> who
Your variables are:

d                mon              date_time        
day              year             date_time_array  

Input Arguments

collapse all

Variables to display, specified as one or more character vectors or string scalars. Use the '*' wildcard to match patterns. For example, who A* S* lists the names of all the variables in the workspace that start with A or S.

Regular expressions that define the variables to display, specified as one or more character vectors or string scalars. For example, who -regexp ^Mon ^Tues lists only the variable names in the workspace that begin with Mon or Tues. For more information about creating regular expressions, see Regular Expressions.

Name of MAT-file, specified as a character vector or string scalar. The file name can include the full, relative, or partial path. For example, who -file myFile.mat lists the names of all variables in the MAT-file named myFile.mat.

Data Types: char | string

Output Arguments

collapse all

List of variables, specified as a cell array of character vector.

Alternatives

  • To view the variables in the workspace, use the Workspace browser. To view the contents of MAT-files, use the Details Panel of the Current Folder browser. In MATLAB Online™, to view the contents of MAT-files, preview them by clicking the Preview button to the right of the MAT-file in the Files browser.

Version History

Introduced before R2006a