why I get "out of memory" error when i use zeros(60000)?
1 view (last 30 days)
Show older comments
Hi. when I use zeros(60000) I receive out of memory error.My matlab product is MATLAB R2014a 64 bit. can you help me please?
0 Comments
Answers (2)
Thorsten
on 16 Nov 2015
You tried to allocate 60000*60000*8 = 28.8 GByte. That's seems to be too much for Matlab on your machine.
3 Comments
Thorsten
on 16 Nov 2015
Edited: Thorsten
on 16 Nov 2015
This traditional convention is not recommended, as far as I understand from https://en.wikipedia.org/wiki/Gigabyte:
In 1998 the International Electrotechnical Commission (IEC) published standards for binary prefixes, requiring that the gigabyte strictly denote 1000^3 bytes and gibibyte denote 1024^3 bytes. By the end of 2007, the IEC Standard had been adopted by the IEEE, EU, and NIST, and in 2009 it was incorporated in the International System of Quantities. Nevertheless, the term gigabyte continues to be widely used with the following two different meanings: [namely 1000^3 and 1024^3]
Guillaume
on 16 Nov 2015
Yes, the notation is not recommended. It is however the one used by the memory manufacturers and the one used by Windows to report the amount of memory your computer has.
Guillaume
on 16 Nov 2015
Edited: Guillaume
on 16 Nov 2015
zeros(60000) is the same as
zeros(60000, 60000)
A 60,000 x 60,000 matrix of doubles requires approximately 27 GB of memory.
If you just want a vector of 60,000 elements:
zeros(1, 60000)
2 Comments
Stefan Raab
on 16 Nov 2015
Hey,
if you use the command
memory
you can see the Maximum possible array size. In my case:
Maximum possible array: 17896 MB (1.877e+10 bytes)
A double variable needs 64 bit or 8 byte of memory, so I can save 1.877e+10 bytes / 8 bytes = 2.3463e+09 double variables in one array. The resulting size for a quadratic matrix is then sqrt(2.3463e+09) = 48438. Therefore is a quadratic matrix with size 60000 too big.
Note: If there are many zeros in your matrix, I think you should have a look at sparse matrices: http://www.mathworks.com/help/matlab/ref/sparse.html
Kind regards, Stefan
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!