matlab out of memory error when multiplying 2 matrix

I have a X = 3*120744 double matrix and I am trying to calculate X'X but getting out of memory error. I have a system with 16G ram. So not sure what's going on. Any idea?

 채택된 답변

Stephan
Stephan 2019년 3월 5일
편집: Stephan 2019년 3월 5일

1 개 추천

Hi,
consider:
X = ones(3,120744);
result_1 = X*X'; % --> Result = 3 x 3 Matrix (72 Byte)
result_2 = X'*X; % --> Result = 120744 x 120744 Matrix (108.6 GB)
Result 2 will throw error:
Requested 120744x120744 (108.6GB) 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.
Error in UASB (line 4)
result_2 = X'*X;
So buy more RAM or think about if you do the right matrix multiplication...
Best regards
Stephan

추가 답변 (1개)

Steven Lord
Steven Lord 2019년 3월 5일
With the specified dimensions, the result of X'*X will be size [120744 120744]. Assuming X is a real, full, double matrix that will require a contiguous block of memory of this size:
>> resultsize = [120744 120744];
>> numberOfElements = prod(resultsize);
>> bytes = 8*numberOfElements; % a real double requires 8 bytes
>> gb = bytes/(1024^3)
gb =
108.622860431671
You likely don't have a contiguous block of memory that large.
If you tell us more about the properties of X and why you're trying to compute X'*X (what your ultimate goal is) we may be able to suggest an alternative. If X is sparsely populated, for example, storing it as a sparse matrix may help.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

MB
2019년 3월 5일

답변:

2019년 3월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by