Find indices of repetitive values
조회 수: 33 (최근 30일)
이전 댓글 표시
In array a=[1,1,1,2,3,4,3]. I want to find indices of repeating (duplicate) values. Finally want to get the repeating value. Short code with commands such as "unique" and "find" is expected.
댓글 수: 1
답변 (2개)
Image Analyst
2017년 11월 11일
편집: Image Analyst
2017년 11월 11일
Use findgroups():
a=[1,1,1,2,3,4,3]
groups = findgroups(a)
Then histogram it to find groups with more than 1 count.
댓글 수: 0
Jan
2017년 11월 11일
편집: Jan
2021년 10월 24일
[B, N, Index] = RunLength(sort(a));
repeated = B(N > 1)
This is the list of values, which occur more than once.
Or:
au = unique(a);
[N, Edge] = histcounts(a, [au, au(end) + 1]);
repeated = au(N > 1)
댓글 수: 6
Image Analyst
2017년 11월 12일
mukund, no that does not clarify, it just says what you originally said. So in my example a=[1,1,1,2,3,4,3, 1,4,4,2,2,3] let's consider the 4th 1. Is that a repeat? It's a repeat of the 1's in the first group, but it's in its own group. And the 1 in the second group of 1 is not repeated in its group - there is just one 1, not multiple 1's in the second group. I asked for the output of my example but you did not give it so I don't know how to help you in the general purpose situation.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!