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

1 次查看(过去 30 天)
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!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-10-26
MatrixAo = MatrixA(abs(MatrixA) > eps(100));
  4 个评论

请先登录,再进行评论。

更多回答(2 个)

José-Luis
José-Luis 2012-10-26
编辑:José-Luis 2012-10-26
your_mat = A(A~=0);
And if you want a sparse matrix:
your_mat = sparse(A);

Sachin Ganjare
Sachin Ganjare 2012-10-26
Try this:
MatrixAo = MatrixA(MatrixA~=0)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by