How can I select all the nonzero elements of a matrix and give out a matrix?
이전 댓글 표시
How can I select all the nonzero elements of a matrix and give out a matrix?
MatrixAo = find(MatrixA(:)~=0)
This only gives the indices back... Is there any better command?
Thanks a lot!
채택된 답변
추가 답변 (2개)
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!