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

MATLABwhos

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

Best Answer

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