How can I select all the nonzero elements of a matrix and give out a matrix?
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (2)
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);
1 commentaire
Simon
le 26 Oct 2012
Sachin Ganjare
le 26 Oct 2012
0 votes
Try this:
MatrixAo = MatrixA(MatrixA~=0)
1 commentaire
Simon
le 26 Oct 2012
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!