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

17 Ansichten (letzte 30 Tage)
Homayoon
Homayoon am 12 Jul. 2016
Kommentiert: Homayoon am 12 Jul. 2016
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.

Akzeptierte Antwort

Homayoon
Homayoon am 12 Jul. 2016
I guess I find it out!!
unique(a(all(a,2),:),'rows')

Weitere Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by