Matlab max array size

3 views (last 30 days)
Alex Hoppus
Alex Hoppus on 25 Feb 2011
Edited: Stephen23 on 24 Oct 2020
Hello everyone. I use matlab for data classification. When i try to create samples array, i get 'out of memory' error. The array size is 25920x1296 data dype - double. So it takes 268.7 Mb. How can i change max matlab array size? Or why this error occurs? I tried to change type of array to int or single, but it didn't works.
Thanks.

Accepted Answer

Matt Tearle
Matt Tearle on 25 Feb 2011
Technically, 25920-by-1296 is 256.3Mb, but let's not quibble over a few meg :)
If you're on a Windows machine, type memory to see what the maximum available variable space is. MATLAB doesn't restrict arrays -- it's really a restriction of your system. So unless you can clear up space in some way, your only option is to crunch down the data or add more memory.
That said, look at doc memory for some ideas.
How are you creating the array? When you say you tried to change type, how did you do that?
  1 Comment
Walter Roberson
Walter Roberson on 25 Feb 2011
If Alex is getting Out Of Memory for an array that small, then chances are quite high that Alex is using a 32 bit version of Matlab, in which case Matlab *does* restrict arrays. rand(10000000) is not going to complain about "out of memory" on such a system: it is going to complain that the number of elements in the array is too high.
Not that this distinction makes any practical difference on a system that can't hold an array that size...

Sign in to comment.

More Answers (1)

Alex Hoppus
Alex Hoppus on 25 Feb 2011
"How are you creating the array? "
I don't know the size of array, so i fill it in this way:
first initialization: array=zeros([],size of descriptor vector);
then filling: array(end+1,:)=descriptor vector;
"When you say you tried to change type, how did you do that? "
in this way: single(array) uint8(array)
So why the type changing doesn't affect to this error? I thought that type changing may solve this problem, because integers takes less memory... or what?
  3 Comments
Walter Roberson
Walter Roberson on 25 Feb 2011
Also, consider using cell arrays to build up the array. Once it is completely built, you can cell2mat() it. This won't get around the size problems, but will be more efficient than growing a numeric array. Pre-allocating will be faster.
Matt Tearle
Matt Tearle on 25 Feb 2011
I was thinking of avoiding that route because it would make the memory problem worse when you do cell2mat... but actually Walter's suggestion does bring up another possibility (dirty, but maybe effective). If the issue is, for whatever reason, the maximum single array size, rather than the overall memory, you might be able to store the data as a cell array, then just access everything with indexing (and probably lots of nasty loops). IANA developer, so don't take this as gospel, but I do know that cell arrays have some memory overhead, but they effectively act like an array of pointers to other memory locations. So if each row of your array was a cell, you'd need space for a 25920-by-1 cell array, which I think would be about 1.5Mb of contiguous space. Then all the elements of the cells could be stored wherever, each needing only 10K of contiguous space. (NB: overall that's more memory, but fragmentation wouldn't be so problematic). I don't really know if that will help, but it's an idea.

Sign in to comment.

Categories

Find more on Characters and Strings 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!