How to get the unique and NON-ZERO rows of a matrix?

조회 수: 16 (최근 30일)
Homayoon
Homayoon 2016년 7월 12일
댓글: Homayoon 2016년 7월 12일
Dear Experts,
I do not know how to get the unique and non-zero rows of a matrix, can you help me to figure it out please?
For example,
a = [1 2 3
0 0 0
2 4 6]
While the following command gives me the unique rows but it includes the Zero rows as well that I do not want to have in my desired output
unique(a,'rows')
my desired output has to be as :
[1 2 3
2 4 6]
thanks for helps.

채택된 답변

Homayoon
Homayoon 2016년 7월 12일
I guess I find it out!!
unique(a(all(a,2),:),'rows')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 7월 12일
row_is_zero = all(a==0,2);
unique( a(~row_is_zero, :), 'rows')
  댓글 수: 1
Homayoon
Homayoon 2016년 7월 12일
Thanks Walter, I did not realize you had answered. Sorry to take your time and I really appreciate your being helpful. Thanks

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

카테고리

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