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

1 Ansicht (letzte 30 Tage)
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 Kommentare
José-Luis
José-Luis am 26 Okt. 2012
And regarding your previous question: don't use globals, you will save someone (probably yourself) a world of hurt in the future.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 26 Okt. 2012
MatrixAo = MatrixA(abs(MatrixA) > eps(100));
  4 Kommentare
Andrei Bobrov
Andrei Bobrov am 26 Okt. 2012
Hi, Jose! Yes, it as arbitrary, from my experience.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

José-Luis
José-Luis am 26 Okt. 2012
Bearbeitet: José-Luis am 26 Okt. 2012
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);

Sachin Ganjare
Sachin Ganjare am 26 Okt. 2012
Try this:
MatrixAo = MatrixA(MatrixA~=0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by