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

1 回表示 (過去 30 日間)
Simon
Simon 2012 年 10 月 26 日
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 件のコメント
José-Luis
José-Luis 2012 年 10 月 26 日
And regarding your previous question: don't use globals, you will save someone (probably yourself) a world of hurt in the future.
Simon
Simon 2012 年 10 月 26 日
I will remember this advice!

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 10 月 26 日
MatrixAo = MatrixA(abs(MatrixA) > eps(100));
  4 件のコメント
José-Luis
José-Luis 2012 年 10 月 26 日
Because of numerical precision issues.
Andrei Bobrov
Andrei Bobrov 2012 年 10 月 26 日
Hi, Jose! Yes, it as arbitrary, from my experience.

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by