Hi, I have a cell array which consists of many sparse matrices. For example:
N.B. In my original problem each sparse matrix is about 4000*4000 in size and has many zero entries
A{1}=sparse(magic(150));A{2}=sparse(magic(150));A{3}=sparse(magic(150));A{4}=sparse(magic(150));....% I want something like:
KK = A{1}+A{2}+A{3}+.... % KK should be a sparse matrix of 150*150
% Adding them in a loop is very time consuming
% I tried the following but did not work:
KK = sum(cat(2,KC{:}),3); % or 1,2 as the sum dimension
% also
KK = sum([KC{:}]); % gives a vector
Best Answer