Filter löschen
Filter löschen

Find indices of repetitive values

30 Ansichten (letzte 30 Tage)
Mukund
Mukund am 11 Nov. 2017
Bearbeitet: Jan am 24 Okt. 2021
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 Kommentar
Jan
Jan am 11 Nov. 2017
What is the wanted output? Is this your homework? What have you tried so far?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 11 Nov. 2017
Bearbeitet: Image Analyst am 11 Nov. 2017
Use findgroups():
a=[1,1,1,2,3,4,3]
groups = findgroups(a)
Then histogram it to find groups with more than 1 count.

Jan
Jan am 11 Nov. 2017
Bearbeitet: Jan am 24 Okt. 2021
[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 Kommentare
Image Analyst
Image Analyst am 12 Nov. 2017
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.
Mukund
Mukund am 12 Nov. 2017
@Jan- Your guess of my expectation is right and this is the required code. Many thanks. I myself tried it in many ways, but no success. Thanks again.
@Image Analyst- Sorry for communication gap from my side. However, Thanks to you for your efforts.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by