Available memory error in MATLAB quiz

Hi,
I am doing a MATLAB related course and came up with this question (attachment), which i couldn't solve by myself. Answers with explanation would really be helpfull.
Thanks.

1 Comment

After running memory, the output is the following:
Which of the following arrays require more than the available memory? (Select all that apply.)

Sign in to comment.

 Accepted Answer

Suppose you have rand(1,1e8) . Then the resulting array will have 1 * 1e8 locations in it, and each one of them will be a double. A double needs 8 bytes, so 1e8 locations would require 8e8 bytes of memory. The available memory is over 1e10 so 8e8 bytes would fit.
Suppose you have rand(1e3) . Then this is not a 1e3 x 1 array, and it is not a 1 x 1e3 array !
It is an oddity of MATLAB then when you pass a scalar to rand() or randn() or zeros() or ones() [or some other functions], that the interpretation is that you are asking for a square array with that size on each side. So rand(1e3) is asking for a 1e3 by 1e3 array. Which would be 1e3*1e3 = 1e6 locations. Each location takes 8 bytes, so that would require 8e6 bytes. The available memory is over 1e10 so 8e6 bytes would fit.
Using this reasoning, you should be able to systematically figure out which of the arrays will fit in just over 1e10 bytes of memory.

1 Comment

Hi Walter,
Thanks for the detailed response. I have got the correct answer which is options c) and e).

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!