| MATLAB Function Reference | ![]() |
As an alternative to whos, use the Workspace browser. Or use the Current Directory browser to view the contents of MAT-files without loading them.
who
whos
who(variable_list)
whos(variable_list)
who(variable_list, qualifiers)
whos(variable_list, qualifiers)
s = who(variable_list, qualifiers)
s = whos(variable_list, qualifiers)
who variable_list qualifiers
whos variable_list qualifiers
Each of these syntaxes apply to both who and whos:
who lists in alphabetical order all variables in the currently active workspace.
whos lists in alphabetical order all variables in the currently active workspace along with their sizes and types. It also reports the totals for sizes.
Note If who or whos is executed within a nested function, the MATLAB® software lists the variables in the workspace of that function and in the workspaces of all functions containing that function. See the Remarks section, below. |
who(variable_list) and whos(variable_list) list only those variables specified in variable_list, where variable_list is a comma-delimited list of quoted strings: 'var1', 'var2', ..., 'varN'. You can use the wildcard character * to display variables that match a pattern. For example, who('A*') finds all variables in the current workspace that start with A.
who(variable_list, qualifiers) and whos(variable_list, qualifiers) list those variables in variable_list that meet all qualifications specified in qualifiers. You can specify any or all of the following qualifiers, and in any order.
Qualifier Syntax | Description | Example |
|---|---|---|
'global' | List variables in the global workspace. | whos('global') |
'-file', filename | List variables in the specified MAT-file. Use the full path for filename. | whos('-file', 'mydata') |
'-regexp', exprlist | List variables that match any of the regular expressions in exprlist. | whos('-regexp', '[AB].', '\w\d') |
s = who(variable_list, qualifiers) returns cell array s containing the names of the variables specified in variable_list that meet the conditions specified in qualifiers.
s = whos(variable_list, qualifiers) returns structure s containing the following fields for the variables specified in variable_list that meet the conditions specified in qualifiers:
Field Name | Description |
|---|---|
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. Set to the string '(unassigned)' if the variable has no value. |
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 having the following fields:
|
persistent | True if the variable is persistent; otherwise false |
who variable_list qualifiers and whos variable_list qualifiers are the unquoted forms of the syntax. Both variable_list and qualifiers are space-delimited lists of unquoted strings.
Nested Functions. When you use who or whos inside of a nested function, MATLAB returns or displays all variables in the workspace of that function, and in the workspaces of all functions in which that function is nested. This applies whether you include calls to who or whos in your M-file code or if you call who or whos from the MATLAB debugger.
If your code assigns the output of whos to a variable, MATLAB returns the information in a structure array containing the fields described above. If you do not assign the output to a variable, MATLAB displays the information at the Command Window, grouped according to workspace.
If your code assigns the output of who to a variable, MATLAB returns the variable names in a cell array of strings. If you do not assign the output, MATLAB displays the variable names at the Command Window, but not grouped according to workspace.
Compressed Data. Information returned by the command whos -file is independent of whether the data in that file is compressed or not. The byte counts returned by this command represent the number of bytes data occupies in the MATLAB workspace, and not in the file the data was saved to. See the function reference for save for more information on data compression.
MATLAB® Objects. whos -file filename does not return the sizes of any MATLAB objects that are stored in file filename.
Show variable names starting with the letter a:
who a*
Show variables stored in MAT-file mydata.mat:
who -file mydata
Return information on variables stored in file mydata.mat in structure array s:
s = whos('-file', 'mydata1')
s =
6x1 struct array with fields:
name
size
bytes
class
global
sparse
complex
nesting
persistentDisplay the name, size, and class of each of the variables returned by whos:
for k=1:length(s) disp([' ' s(k).name ' ' mat2str(s(k).size) ' ' s(k).class]) end A [1 1] double spArray [5 5] double strArray [2 5] cell x [3 2 2] double y [4 5] cell
Show variables that start with java and end with Array. Also show their dimensions and class name:
whos -file mydata2 -regexp \<java.*Array\> Name Size Bytes Class javaChrArray 3x1 java.lang.String[][][] javaDblArray 4x1 java.lang.Double[][] javaIntArray 14x1 java.lang.Integer[][]
The function shown here uses variables with persistent, global, sparse, and complex attributes:
function show_attributes persistent p; global g; o = 1; g = 2; s = sparse(eye(5)); c = [4+5i 9-3i 7+6i]; whos
When the function is run, whos displays these attributes:
show_attributes Name Size Bytes Class Attributes c 1x3 48 double complex g 1x1 8 double global p 1x1 8 double persistent s 5x5 84 double sparse
Function whos_demo contains two nested functions. One of these functions calls whos; the other calls who:
function whos_demo
date_time = datestr(now);
[str pos] = textscan(date_time, '%s%s%s', ...
1, 'delimiter', '- :');
get_date(str);
str = textscan(date_time(pos+1:end), '%s%s%s', ...
1, 'delimiter', '- :');
get_time(str);
function get_date(d)
day = d{1}; mon = d{2}; year = d{3};
whos
end
function get_time(t)
hour = t{1}; min = t{2}; sec = t{3};
who
end
endWhen nested function get_date calls whos, MATLAB displays information on the variables in all workspaces that are in scope at the time. This includes nested function get_date and also the function in which it is nested, whos_demo. The information is grouped by workspace:
whos_demo Name Size Bytes Class ---- get_date ----------------------------------------- d 1x3 378 cell day 1x1 64 cell mon 1x1 66 cell year 1x1 68 cell ---- whos_demo ---------------------------------------- ans 0x0 0 (unassigned) date_time 1x20 40 char pos 1x1 8 double str 1x3 378 cell
When nested function get_time calls who, MATLAB displays names of the variables in the workspaces that are in scope at the time. This includes nested function get_time and also the function in which it is nested, whos_demo. The information is not grouped by workspace in this case:
Your variables are: hour min sec t ans date_time pos str
assignin, clear, computer, dir, evalin, exist, inmem, load, save, what, workspace
![]() | whitebg | wilkinson | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |