Skip to Main Content Skip to Search
Product Documentation

who - List variables in workspace

Syntax

who
who(variables)
who(location)
who(variables,location)
c = who(variables,location)

Description

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

who(variables) lists only the specified variables.

who(location) lists variables in the specified location: 'global' for the global workspace, or '-file' for a MAT-file. For MAT-files, you must also include the file name as an input.

who(variables,location) lists the specified variables in the specified location. The location input can appear before or after variables.

c = who(variables,location) stores the names of the variables in cell array c. Specifying variables and location is optional.

Tips

Input Arguments

variables

Strings that specify the variables to list. Use one of these forms:

var1, var2, ...

List the specified variables.
Use the '*' wildcard to match patterns. For example, who('A*') lists all variables that start with A.

'-regexp', expressions

List variables whose names match the specified regular expressions.

Default: '*' (all variables)

location

String that indicates whether to list variables from the global workspace or from a file:

'global'

Global workspace.

'-file', filename

MAT-file. The filename input can include the full, relative, or partial path.

Default: '' (current workspace)

Output Arguments

c

Cell array of strings that correspond to each variable name.

Examples

Display information about variables in the current workspace whose names start with the letter a:

who a*
 

Show variables stored in MAT-file durer.mat:

who -file durer

This code returns:

Your variables are:

X        caption  map   
 

Store the variable names from durer.mat in cell array durerInfo:

durerInfo = who('-file', 'durer');

Display the contents of cell array durerInfo:

for k=1:length(durerInfo)
   disp(durerInfo{k})
end

This code returns:

  X
  caption
  map
 

Suppose that a file mydata.mat contains variables with names that start with java and end with Array. Display information about those variables:

 whos -file mydata -regexp \<java.*Array\>
 

Call who within a nested function (get_date):

function who_demo
date_time = datestr(now);
 
[str pos] = textscan(date_time, '%s%s%s', ...
                     1, 'delimiter', '- :');
get_date(str);

   function get_date(d)
      day = d{1};
      mon = d{2};
      year = d{3};
      who
   end

end

When you run who_demo, the who function displays the variables by function workspace (although the name of the function does not appear in the output):

Your variables are:

d          mon        ans        pos        
day        year       date_time  str 

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.

See Also

assignin | clear | dir | evalin | exist | inmem | load | save | what | whos | workspace

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS