Skip to Main Content Skip to Search
Product Documentation

whos - List variables in workspace, with sizes and types

Syntax

whos
whos(variables)
whos(location)
whos(variables,location)
s = whos(variables,location)

Description

whos lists in alphabetical order all variables in the currently active workspace, including their sizes and types.

whos(variables) lists only the specified variables.

whos(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.

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

s = whos(variables,location) stores information about the variables in structure s. 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, whos('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

s

Nested structure array that contains a scalar struct for each variable. Each scalar struct contains these fields:

name

Name of the variable.

size

Dimensions of the variable array.

bytes

Number of bytes allocated for the variable array.

class

Class of the variable. If the variable has no value, class is '(unassigned)'.

global

True if the variable is global; otherwise, false.

sparse

True if the variable is sparse; otherwise, false.

complex

True if the variable is complex; otherwise, false.

nesting

Structure with these fields:

  • function — Name of the nested or outer function that defines the variable.

  • level — Nesting level of that function.

persistent

True if the variable is persistent; otherwise, false.

Examples

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

whos a*
 

Show variables stored in MAT-file durer.mat:

whos -file durer

This code returns:

  Name           Size               Bytes  Class     Attributes

  X            648x509            2638656  double              
  caption        2x28                 112  char                
  map          128x3                 3072  double
 

Store information about the variables from durer.mat in structure array durerInfo:

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

Display the contents of structure durerInfo:

  for k=1:length(durerInfo)
   disp(['  ' durerInfo(k).name ...
         '  ' mat2str(durerInfo(k).size) ...
         '  ' durerInfo(k).class]);
end

This code returns:

  X  [648 509]  double
  caption  [2 28]  char
  map  [128 3]  double
 

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\>
 

Create a function that displays information about variables with persistent, global, sparse, and complex attributes:

function show_attributes
persistent p;
global g;
p = 1;
g = 2;
s = sparse(eye(5));
c = [4+5i 9-3i 7+6i];
whos

When you call the function, show_attributes displays the attributes:

Name      Size            Bytes  Class     Attributes

c         1x3                48  double    complex   
g         1x1                 8  double    global    
p         1x1                 8  double    persistent
s         5x5               128  double    sparse    
 

Call whos within a nested function (get_date):

function whos_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};
      whos
   end

end

When you run whos_demo, the whos function displays the variables by function workspace:

Name           Size        Bytes  Class         Attributes

---- get_date --------------------------------------------
d              1x3           690  cell                    
day            1x1           116  cell                    
mon            1x1           118  cell                    
year           1x1           120  cell                    

---- whos_demo -------------------------------------------
ans            0x0             0  (unassigned)            
date_time      1x20           40  char                    
pos            1x1             8  double                  
str            1x3           690  cell                    

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 | who | workspace

  


» Learn more
» Download free kit
» Get trial software

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