Matlab max array size
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex Hoppus
am 25 Feb. 2011
Bearbeitet: Stephen23
am 24 Okt. 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.
0 Kommentare
Akzeptierte Antwort
Matt Tearle
am 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 Kommentar
Walter Roberson
am 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...
Weitere Antworten (1)
Alex Hoppus
am 25 Feb. 2011
3 Kommentare
Walter Roberson
am 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
am 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.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!