How to replace the elements in a big sparse matrix?
问题 I have quite a big sparse matrix, about 150,000*150,000. I need to access into its rows, extract the non-zero elements and replace these values following the rule as as the code below: H = []; for i = 1: size(A,2) [a,b,c] = find(A(i,:)); % extract the rows if size(c,2)==1 % only 2 add = 0; elseif size(c,2) > 1 && any(c<2)== 0 % many 2s add = c; add(1) = -2; add(end) = 2; add(2:end-1) = 0; elseif size(c,2) > 1 && any(c<2)~= 0 % 2 and 1 k = find(diff(c)==-1); % find right 2 position add = c;