Find values in list that appear exactly once

12 vues (au cours des 30 derniers jours)
Johannes Korsawe
Johannes Korsawe le 25 Août 2017
Commenté : Stephen23 le 17 Juil 2021
Hi there,
assume, i have a list of integer values. I need a fast way to find those values in the list, that appear exactly once.
By now i have a code that finds the duplicate values and dismisses them.
list = randi(100,100,1); % Generate a list which should contain duplicate values
[vals,i]=sort(list);
j=find(all(diff(vals)==0,2));
ii=i([j;j+1]);
list(ii)=[];
Is there a faster way to get the final result?
Cheers, Johannes

Réponse acceptée

Stephen23
Stephen23 le 25 Août 2017
Modifié(e) : Stephen23 le 25 Août 2017
How about this:
[tmp,idx] = sort(list);
idp = diff(tmp)>0;
list(idx([true;idp]&[idp;true]))
If you are okay with getting the output sorted then it can be simplified further:
tmp = sort(list);
idp = diff(tmp)>0;
tmp([true;idp]&[idp;true])
  3 commentaires
Mohammadreza Mahmoodi
Mohammadreza Mahmoodi le 17 Juil 2021
what is idp means ?
Stephen23
Stephen23 le 17 Juil 2021
@Mohammadreza Mahmoodi: idp is a logical vector which indicates where the values change.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by