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!
  댓글 수: 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.

댓글을 달려면 로그인하십시오.

채택된 답변

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by