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!