List variables in workspace, with sizes and types




whos displays in alphabetical order all variables in the currently active workspace, with information about their sizes and types.


whos(variables) displays only the specified variables.


whos(location) displays variables in the specified location.

whos(variables,location) displays the specified variables in the specified location. The location and variables inputs can appear in either order.


S = whos(___) stores information about the variables in structure array, S, using no input arguments, or any of the input arguments from the previous syntaxes.


collapse all

Display Information About Workspace Variables

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


Display Variables Stored in a MAT-File

Display all variables stored in the sample MAT-file, durer.mat.

  Name           Size               Bytes  Class     Attributes

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

Show only variables in the MAT-file with names that end with ion.

  Name         Size            Bytes  Class    Attributes

  caption      2x28              112  char               

Store Variable Information in a Structure Array

Store information about the variables in durer.mat in structure array S.

S = whos('-file','durer.mat');

Display the contents of S.

for k = 1:length(S)
   disp(['  ' S(k).name ...
         '  ' mat2str(S(k).size) ...
         '  ' S(k).class]);
  X  [648 509]  double
  caption  [2 28]  char
  map  [128 3]  double

Create Function to Display Variable Attribute Information

In the Editor, create a function that creates variables with various persistent, global, sparse, and complex attributes, and then displays information about them.

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

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 or Anonymous Function

Create a function, whos_demo, that contains a nested function, get_date. Call whos within the nested function.

function whos_demo
date_time = datestr(now);
C = strsplit(date_time,{'-',''});

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


When you run the whos_demo function, whos displays the variables of the nested get_date function, and all functions that contain it, grouped by function workspace. This grouping applies whether you call whos from your function code or from the MATLAB® debugger.

  Name           Size            Bytes  Class           Attributes

  ---- get_date --------------------------------------------------
  d              1x3               372  cell                      
  day            1x2                 4  char                      
  mon            1x3                 6  char                      
  year           1x13               26  char                      

  ---- whos_demo -------------------------------------------------
  C              1x3               372  cell                      
  ans            0x0                 0  (unassigned)              
  date_time      1x20               40  char                      

When called within an anonymous function, variables in the anonymous function also display in a group, titled with the function signature

Input Arguments

collapse all

variables — Variables to displaystrings

Variables to display, specified as one or more strings in one of the following forms.

Form of Variables InputVariable Names
var1 ... varNList the named variables, specified as individual strings.
Use the '*' wildcard to match patterns. For example, whos('A*') lists all variables in the workspace that start with A.
'-regexp',expr1 ... exprNList only the variables that match the regular expressions, specified as strings. For example, whos('-regexp','^Mon','^Tues') lists only the variables in the workspace that begin with Mon or Tues.

location — Location of variables'global' | '-file',filename

Location of variables, specified as one of the following strings.

Value of locationLocation of Variables
'global'Global workspace.

MAT-file. The filename input can include the full, relative, or partial path. For example, whos('-file','myFile.mat') lists all variables in the MAT-file named myFile.mat.

whos('-file',filename) does not return the sizes of any MATLAB objects in file filename.

Output Arguments

collapse all

S — Information about variablesnested structure array

Information about variables, returned as a nested structure array that contains a scalar struct for each variable. Each scalar struct contains these fields.



Name of the variable.


Dimensions of the variable array.


Number of bytes allocated for the variable array.


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


True if the variable is global; otherwise, false.


True if the variable is sparse; otherwise, false.


True if the variable is complex; otherwise, false.


Structure with these fields:

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

  • level — Nesting level of that function.


True if the variable is persistent; otherwise, false.

More About

expand all


  • You also can view the contents of MAT-files using the Details Panel of the Current Folder browser.


whos returns the number of bytes each variable occupies in the workspace, not in a MAT-file. Version 7 MAT-files and later are compressed, so the number of bytes in the file is typically fewer than the number of bytes required in the workspace.

See Also

| | |

Introduced before R2006a

Was this topic helpful?