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!