in the old old days, whos function also give total variable size, how do i do that now [ver 9.4.0.813654 (R2018a)]

1 view (last 30 days)
I remember in the old old days, whos function also give total variable size, how do i do that now [ver 9.4.0.813654 (R2018a)].
I never have the need to do that till now and I am too lazy to copy and paste and sum the variable size for each variable.
I want to check the total amount of storage needed if I store the variables that were specified in whos.
Thanks
Steve Leung
  4 Comments
Stephen Leung
Stephen Leung on 15 Feb 2019
sorry using length as suggested in the answer will not work. let me give you my example:
I have the following variables:
dish_noise, dish_signal, dish_interference
array_noise, array_signal, array_interference.
I execute the command: whos dish* array*
the 3rd column of the output gives me the byte size for each variable
I am too lazy to copy the output of the whos command into my editor and spend time editor the untitled file to generate the code to sum bytes of the variables
of course, I can do:
(length(dish_noise)+length(dish_signal)+...+length(array_interference))*16
if all my variables are complex-double
but what if some of them are real, some of them are logical?
what if I want to store only 50 of of the 100 variables that I have in the workspace?

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 15 Feb 2019
You call whos as normal?
>> x = magic(4);
>> y = struct('foo', 1, 'bar', 2);
>> z = ["apple"; "banana"; "cherry"];
>> whos
Name Size Bytes Class Attributes
x 4x4 128 double
y 1x1 368 struct
z 3x1 258 string
Because the whos function still returns the size of the variable when called on normal workspace variables, there has to be more to your question. How exactly are you calling whos and on what type of variable are you calling it?
I want to check the total amount of storage needed if I store the variables that were specified in whos.
Note that this may get tricky if you take into account the copy-on-write behavior of MATLAB. A copy of a variable may look like it takes up the same amount of space as the original, but it may share a substantial chunk of that memory. The bytes column of the output of whos also does not account for object properties, like the properties of a graphics object.
>> [x, y, z] = peaks;
>> h = surf(x, y, z);
>> whos x y z h
Name Size Bytes Class Attributes
h 1x1 8 matlab.graphics.chart.primitive.Surface
x 49x49 19208 double
y 49x49 19208 double
z 49x49 19208 double

More Answers (0)

Tags

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!