Concatenating large matrices - out of memory

조회 수: 11 (최근 30일)
John
John 2013년 3월 12일
I have four 4096x4096 sparse matrices namely A, B, C, and D and they only have elements on the diagonal.
I tried to make a matrix X = [ A B; C D] which is 8192x8192 but I get an out of memory error.
Essentially, I need to multiply X with a 8192x1 vector Y.
Is there a more sophisticated way to do this?

채택된 답변

Matt J
Matt J 2013년 3월 12일
편집: Matt J 2013년 3월 12일
X=[sparse(A),sparse(B);sparse(C), sparse(D)];
result = X*Y;
Or,
a=diag(A);
b=diag(B);
c=diag(C);
d=diag(D);
y1=Y(1:4096);
y2=Y(4097:end);
result = [a.*y1+b.*y2; c.*y1 + d.*y2];
  댓글 수: 2
John
John 2013년 3월 12일
Thanks but for your first solution, A, B , C, and D are already sparse. Does it change anything if you apply the sparse function again when it's being concatenated.
Matt J
Matt J 2013년 3월 12일
Are you sure they are already sparse? Or, are you sure the out-of-memory is coming from the statement X=[A B;C D]?
It doesn't make sense that diagonal sparse matrices of that size would give you any problems with memory. If you are on a 32 bit machine and you accidentally made those matrices non-sparse, I could see you getting such an error

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Konrad Malkowski
Konrad Malkowski 2013년 3월 12일
Have you tried explicitly storing the matrix as sparse?

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by