How do I delete repetitions of rows in a matrix?

Suppose I have the following matrix (the one I'm working on has 1000x1000 cells, so I'll simplify things):
a=[1,2,3; 8,7,8; 1,2,3; 5,6,0; 2,5,7; 2,5,7];
I want to get rid of rows that repeat themselves, so that I have one row left from each repetition set. The desired matrix in this case would be:
a=[1,2,3; 8,7,8; 5,6,0; 2,5,7];
How do I do this?

 採用された回答

Ahmet Cecen
Ahmet Cecen 2015 年 5 月 7 日

0 投票

C = unique(A,'rows')

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2015 年 5 月 7 日

1 投票

out = unique(A,'rows','stable');
old version of MATLAB:
[~,b] = unique(A,'rows','first');
out = A(sort(b),:);

2 件のコメント

Natalie
Natalie 2015 年 5 月 7 日
Thanks!
I tried C=unique(A, 'rows'), as suggested. What does the 'stable' add?
Guillaume
Guillaume 2015 年 5 月 7 日
'stable' keeps the rows in the order they first appear. If not specified, then unique return the rows in a sorted order.

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2015 年 5 月 7 日

コメント済み:

2015 年 5 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by