File Exchange

image thumbnail

Display ws variables size in KB, MB or GB

version 1.6 (3.49 KB) by

Displays with appropriate unit of data storage. Sorting by size/name (non c.sensitive) is supported.

7 Ratings



View License

Display in command window the size of the variables of the base workspace using KB, MB and GB

(1) WSSIZE Display preserving the order of the workspace pane using mixed units
(2) WSSIZE arg or WSSIZE('arg') One argument syntax
(3) WSSIZE arg1 arg2 or WSSIZE('arg1','arg2') Two arguments syntax

From p7v5 displays the grand total.

Arguments: should be char; max two arguments are allowed. Arguments are not case-sensitive.The order of the two types of arguments doesn't matter. Shortened arguments can be supplied ('s' instead of 'size').

For details see help
For examples see the attached image.

Aknowledgments: original idea by Bastiaan Zuurendonk, TMW technical support engineer. Implemented suggestions by Yair Altman (see comments)

Comments/suggestions/error reports are welcome.

Comments and Ratings (12)

Very easy to use. Thanks!

Dan Kominsky

Thanks so much for this posting this. It has inspired me to create a function named figurememory ( which approximates the amount of memory used by figures and integrating it into my copy of wssize. In the case that one has figures consuming a large amount of memory, it can help identify which figures is doing so. I integrated it into wssize by adding the following lines after the command:
ws_contents = evalin('caller', 'whos');

%% New code:
% Now find the figure memories:
tmp = findall(groot,'Type','Figure');
for i = 1:numel(tmp)
nEntries = numel(ws_contents);
ws_contents(nEntries+1).name = sprintf('** figure %d', tmp(i).Number);
ws_contents(nEntries+1).bytes = figurememory(tmp(i));

Oleg Komarov

Oleg Komarov (view profile)

@Mirsad happy you like it! You can also simply write: wssize m s.

Saves you the effort of writing quotes and parentheses.

Mirsad Tulic

The variant wssize('MB','size') is great!! Clearly arranged and in MB, so the larger variables are seen very nicely at the end.
Thanks to Oleg!


Casper (view profile)

Oleg Komarov

Oleg Komarov (view profile)

You're suggestion to subject the Grand Total to the reverse sorting behaviour?...I'd implement it always as the last entry because when you have many variables the listing on the screen scrolls down a lot...and I'd like to know at a glance how much memory I'm using. Revsorting would flip GT on top and i would miss it...

What about
a: 432 KB
b: 23 KB
T: 455 KB

Where "a" and "b" are subject to the sorting while T: is not?


Nice and usefull tool. Exactly what I was looking for. I would also find an entry "Grand Total" helpful, for example by adding the lines
ws_contents(end+1,:) = { 'Grand Total', sum( cell2mat(ws_contents(:,2)) )};
numVars = numVars+1;
after line 95.

Rob Campbell

Rob Campbell (view profile)

Always wanted this behaviour from whos. Glad to find this file.

Oleg Komarov

Oleg Komarov (view profile)

you're are totally right if syntax consistancy is what we are looking for...and it may be, but when I set the default behavior for the size sorting method I was thinking that maybe displaying first the biggest vars would save some time (if you already have 50 other vars and to see them all scrolling is needed).
On the other hand as you say 'wssize -s' isn't that different from 'wssize s'...I simply didn't want to write every time '-s' (since i'm inerested in many cases in large vars.).
To make it consistent accross methods or not...this is my dilemma..


Andy (view profile)

A minor point: I would switch the size and -size flags so that wssize size sorts from smallest to largest. This is consistent with wssize name sorting in ascending order and wssize -name sorting in descending order.

Oleg Komarov

Oleg Komarov (view profile)

Thanks Yair for the comments (of course I will implement your java suggestion, since that was what I wanted specifically to achieve, still this fcn remains useful)
The features suggested by Yair are being uploaded. Additionally, the workspace variables whose data size will be displayed will change from 'base' to 'caller', making it possible to display the size of the variables during debug. Other updates will be notified in the update frame (below) and inside the fcn. Compatibility unchanged.

Yair Altman

Yair Altman (view profile)

Nice and useful implementation.

I suggest adding reverse sorting by simply prepending '-' (for example: '-size'). I also suggest adding an option to display all the sizes in a particular format (for example: 'KB' or 'MB').

Also see for how to display similar results in the Workspace Panel table.



Per Michael suggestion added grand total at the bottom. Restructured code.


Now 'size' sorts from smallest to biggest. Suggestion by Andy.


From 'base' to 'caller' size display.


Added reverse sorting and unit selection on suggestion by Yair Altman. Edited help. Added more checks.


Edited description; Added sorting by not case-sensitive name; Aknowledgments for Bastiaan Zuurendonk (TMW technical support engineer)

MATLAB Release
MATLAB 7.9 (R2009b)

Inspired: figurememory(h)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video