MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
D = 'Company Name: MathWorks';

s = struct('f1', A, 'f2', B, 'f3', C, 'f4', D);

for m=1:6
for n=1:5
s(m,n)=s(1,1);
end
end

Calculate the amount of memory required for the structure itself, and then for the data it
contains:

structure = fields x ((60 x array elements) + 64) =
4 x ((60 x 30) + 64) = 7,456 bytes

data = (field1 + field2 + field3 + field4) x array elements =
(240 + 2000 + 1800 + 54) x 30 = 122,820 bytes

Add the two, and then compare your result with the size returned by MATLAB:

Total bytes calculated for structure s: 7,456 + 122,820 = 130,276

whos s
Name Size Bytes Class Attributes

s 6x5 130036 struct

29 Memory Usage

Free download pdf