4 way.
Find the indices of the desired matrix elements and the desired matrix elements themselves. With these 3 vectors, rebuild the sparse Matrix M1.
[i1,~,s1] = find(M1(abs(M1)>1e-1));
[i1,j1] = ind2sub(size(M1),i1);
M1 = sparse(i1,j1,s1,m,n);
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!