Concatenating large matrices - out of memory

14 views (last 30 days)
John on 12 Mar 2013
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?

Accepted Answer

Matt J
Matt J on 12 Mar 2013
Edited: Matt J on 12 Mar 2013
X=[sparse(A),sparse(B);sparse(C), sparse(D)];
result = X*Y;
result = [a.*y1+b.*y2; c.*y1 + d.*y2];
Matt J
Matt J on 12 Mar 2013
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

Sign in to comment.

More Answers (1)


Community Treasure Hunt

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

Start Hunting!

Translated by