Sum over cell array of sparse matrices

1 Ansicht (letzte 30 Tage)
Gobi
Gobi am 2 Apr. 2017
Kommentiert: Gobi am 2 Apr. 2017
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?

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by