Quick method to find duplicates in a matrix?

43 vues (au cours des 30 derniers jours)
Dan
Dan le 16 Juil 2014
Commenté : Dan le 16 Juil 2014
Hi guys,
Does anybody know a quick way of checking to see which elements of a matrix are duplicates?
Such as:
a = [1,2,3,4,5,5,1,6,7];
Can we have matlab return the indices of all 1's and 5's or return: 1, 5
Thanks!
  1 commentaire
José-Luis
José-Luis le 16 Juil 2014
What is an element is repeated more than two times?

Connectez-vous pour commenter.

Réponse acceptée

Joseph Cheng
Joseph Cheng le 16 Juil 2014
Modifié(e) : Joseph Cheng le 16 Juil 2014
You can try:
[uniqueA i j] = unique(A,'first');
indexToDupes = find(not(ismember(1:numel(A),i)))
There may be some parameters in the unique() function to get exactly what you desire but i don't remember it off hand.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 16 Juil 2014
Modifié(e) : Azzi Abdelmalek le 16 Juil 2014
a = [1,2,3,4,5,5,1,6,9];
[ii,jj,kk]=unique(a)
out=ii(histc(kk,1:numel(ii))>1)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by