Sum over cell array of sparse matrices

조회 수: 2 (최근 30일)
Gobi
Gobi 2017년 4월 2일
댓글: Gobi 2017년 4월 2일
I have 100 sparse matrices of size N by N, where N=65536.
They have about 5500000 nonzero elements(0.13% of N^2) close to the diagonal.
They are stored in a cell array, S{1}, ... , S{100}, and I want to compute the sum S{1}+...+S{100}.
Sum=sparse(N,N);
for i=1:100
Sum=Sum+S{i};
end
The above for loop code took about 25 seconds. Is there any way to optimize this code?

답변 (1개)

Stalin Samuel
Stalin Samuel 2017년 4월 2일
v1=[S{1:100}];
Sum=sum(v1);
  댓글 수: 1
Gobi
Gobi 2017년 4월 2일
This code gives a 1 by N*100 vector. v1 is a matrix stacking S{:}, and just summing up is not what I want.

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

카테고리

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