finding and storing non zero elements in a NxN matrix
4 ビュー (過去 30 日間)
古いコメントを表示
Hi, I would like to know how i can determine the non zero elements in a matrix consisting mostly of zeros and store its matrix coordinate positions. So in a 64*64 matrix i can determine the non zero elements by making a for loop like this for ix=1:n
for iy=1:n
if newpositions(ix,iy)==0
%nah u alrite
else
newpsi(ix,iy)=%%%here i want to store the ix and iy elements in an array instead of storing them in a huge ix*iy matrix
end
end
end
0 件のコメント
回答 (2 件)
Jos (10584)
2014 年 10 月 2 日
help find
M = rand(5) < 0.2 ; % some data
[r,c,v] = find(M) ; % row and column indices of non-zero elements (with values v)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!