Find indices of repetitive values
34 次查看(过去 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!