| Contents | Index |
whos
whos(variables)
whos(location)
whos(variables,location)
s = whos(variables,location)
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.
The whos function displays the variable list unless you specify an output argument.
whos returns the number of bytes each variable occupies in the workspace, not in a MAT-file. Version 7 and later MAT-files (the default starting with R2006b) are compressed, so the number of bytes in the file is typically less than the number of bytes required in the workspace.
whos -file filename does not return the sizes of any MATLAB objects in file filename.
When used within a nested function, whos lists the variables in the workspaces of that function and all functions containing that function, grouped by workspace. This applies whether you call whos from your function code or from the MATLAB debugger.
variables |
Strings that specify the variables to list. Use one of these forms:
Default: '*' (all variables) | ||||
location |
String that indicates whether to list variables from the global workspace or from a file:
Default: '' (current workspace) |
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]);
endThis 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
endWhen 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
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.
assignin | clear | dir | evalin | exist | inmem | load | save | what | who | workspace
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |