Effacer les filtres
Effacer les filtres

Removing duplicate strings from an array and original

83 vues (au cours des 30 derniers jours)
Declan Bourke
Declan Bourke le 8 Août 2016
Commenté : Declan Bourke le 8 Août 2016
so i'm having trouble trying to eliminate repetitions from my arrays. i've been using unique but can't have the first instance of the element in the return. I'm also dealing with strings as opposed to numerical arrays. for example:
A = AA,AB,AC,AA,AD,AE; B = unique(A); B = AA,AB,AC,AD,AE
what i'm actually looking for is B = AB,AC,AD,AE where even the first instance of repeating elements is taken out. is this possible?
Thanks

Réponse acceptée

Stephen23
Stephen23 le 8 Août 2016
Modifié(e) : Stephen23 le 8 Août 2016
You can use much the same method as in my answer to your last question. Assuming that the strings are in a cell array:
>> A = {'AA','AF','AB','AC','AA','AD','AE'};
>> [~,X,Z] = unique(A,'stable') % remove 'stable' to get sorted output
>> Y = histc(Z,1:numel(X))<2
>> A(X(Y))
ans =
'AF' 'AB' 'AC' 'AD' 'AE'
If the data is all in one string then use strsplit or regexp first.
  1 commentaire
Declan Bourke
Declan Bourke le 8 Août 2016
Thats working great, thanks for the help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings 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