MATLAB array size limit error - why?
35 次查看(过去 30 天)
显示 更早的评论
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 个评论
dpb
2015-10-18
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).
回答(2 个)
Walter Roberson
2015-10-18
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 个评论
Andres
2015-10-19
编辑:Andres
2015-10-19
6 个评论
Mishary Alfarah
2019-4-13
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!