How can I select all the nonzero elements of a matrix and give out a matrix?
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (2)
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);
1 Kommentar
Simon
am 26 Okt. 2012
Sachin Ganjare
am 26 Okt. 2012
0 Stimmen
Try this:
MatrixAo = MatrixA(MatrixA~=0)
1 Kommentar
Simon
am 26 Okt. 2012
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!