Borrar filtros
Borrar filtros

How can I select all the nonzero elements of a matrix and give out a matrix?

1 visualización (últimos 30 días)
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 comentarios
José-Luis
José-Luis el 26 de Oct. de 2012
And regarding your previous question: don't use globals, you will save someone (probably yourself) a world of hurt in the future.

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 26 de Oct. de 2012
MatrixAo = MatrixA(abs(MatrixA) > eps(100));
  4 comentarios
Andrei Bobrov
Andrei Bobrov el 26 de Oct. de 2012
Hi, Jose! Yes, it as arbitrary, from my experience.

Iniciar sesión para comentar.

Más respuestas (2)

José-Luis
José-Luis el 26 de Oct. de 2012
Editada: José-Luis el 26 de Oct. de 2012
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);

Sachin Ganjare
Sachin Ganjare el 26 de Oct. de 2012
Try this:
MatrixAo = MatrixA(MatrixA~=0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by