Find the range of duplicates in a sorted element
Afficher commentaires plus anciens
So let's say I have a vector
a = [6 2 2 5]
I sort it with the function and now:
a = [2 2 5 6]
How do I find the range of the duplicate number(2)? Like, I want it to tell me the start of the duplicte(element1) and the end of the duplicates(element2)
An if I have [2 2 5 5 6]
It tells me copies are in 1-2 and 3-5
Réponse acceptée
Plus de réponses (1)
Thorsten
le 30 Avr 2025
If you are just looking for pairs, you can use
b = sort(a);
startloc = find(diff(b) == 0);
endloc = startloc + 1;
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!