How can I select all the nonzero elements of a matrix and give out a matrix?
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (2)
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);
1 Commento
Simon
il 26 Ott 2012
Sachin Ganjare
il 26 Ott 2012
0 voti
Try this:
MatrixAo = MatrixA(MatrixA~=0)
1 Commento
Simon
il 26 Ott 2012
Categorie
Scopri di più su Resizing and Reshaping Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!