How can I select all the nonzero elements of a matrix and give out a matrix?
Mostrar comentarios más antiguos
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!
Respuesta aceptada
Más respuestas (2)
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);
1 comentario
Simon
el 26 de Oct. de 2012
Sachin Ganjare
el 26 de Oct. de 2012
0 votos
Try this:
MatrixAo = MatrixA(MatrixA~=0)
1 comentario
Simon
el 26 de Oct. de 2012
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!