MATLAB array size limit error - why?
34 views (last 30 days)
Show older comments
I am receiving an unexpected error because of an array allegedly exceeding the maximum array size limit with a non-double type variable.
Here is a short example to reproduce the error:
First, to keep the example variables small, go to preferences -> MATLAB -> workspace and set the limit of the maximum array size temporarily to 1% of the RAM.
You may provoke the correct error with a double array demanding too much memory:
[~,sys] = memory;
testLen = round(sys.PhysicalMemory.Total/100/2);
N = zeros(testLen,1);
Error using zeros
Requested 62859407x1 (0.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
(for 12GB of RAM)
A uint8 array of the same length is ok:
n = zeros(testLen,1,'uint8');
returns no error. You can manipulate it by
n(end) = uint8(1);
as expected.
N(end-5:end).'
gives
0 0 0 0 0 1
But why do
n(end-1:end) = uint8(1);
% or
n(end-1:end) = uint8([1;1]);
and similar manipulations error:
Requested 62859405x1 (0.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information.
?
Is MATLAB (R2015b) simply miscalculating the array memory size for non-doubles here or am I doing something wrong?
2 Comments
dpb
on 18 Oct 2015
Looks like the former to me...like end is coded only for double and not the class of the array at hand would be the likely candidate for the problem.
I hadn't realized that was a user preference; don't see it in R2012b so gather mayhaps it is a newer introduction. If so, would seem quite possible it's not been too thoroughly test as yet; I'd suggest bug report is in order (altho you might want to see if anybody else has alternate explanations first).
Answers (2)
Walter Roberson
on 18 Oct 2015
n(end-1:end) = uint8(1) may require that n be duplicated if n is an array that is currently shared. For example if n is a parameter passed in, and is not being used in the restricted context
n = SomeFunction(n)
whose header is
function n = SomeFunction(n)
then MATLAB may well need to duplicate the array.
0 Comments
Andres
on 19 Oct 2015
Edited: Andres
on 19 Oct 2015
6 Comments
Mishary Alfarah
on 13 Apr 2019
I uchecked that limit and on my activity monitor it showed that it took 63 GB of RAM! then it immediately quit. I think keeping it on maximum maybe is better than uncheck it.
See Also
Categories
Find more on Install Products in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!