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?
'stable' keeps the rows in the order they first appear. If not specified, then unique return the rows in a sorted order.

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

카테고리

도움말 센터File Exchange에서 Matrix 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