MATLAB Answers

Find non unique string in a table

5 views (last 30 days)
Sonima
Sonima on 6 Aug 2019
Answered: Sonima on 9 Aug 2019
Hi!
I have a table "TT" which I want to return the "Ticket" of non unique string in the "Alpha".
TT =
8×2 table
Ticket Alpha
_______ ________
29991 AB'
29991 CD'
29993 EF'
30018 GH'
30066 IJ'
30105 KL'
30105 EF'
30107 NO'
here EF in not unique under "Alpha" and I want to return "30105". How can i do this?

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 6 Aug 2019
Edited: Adam Danz on 8 Aug 2019
nonUnqIdx is a logical index of rows of TT.Alpha that are a repeat (ie, not the first instance).
[~, AlphaGroups] = ismember(TT.Alpha, unique(TT.Alpha,'stable')); % identify groups
nonUnqIdx = [1;diff(AlphaGroups)] < 1;
% Tickets for all non-unique (ie repeat) strings in Alpha
TT.Ticket(nonUnqIdx)

  0 Comments

Sign in to comment.

More Answers (2)

Sean de Wolski
Sean de Wolski on 8 Aug 2019
n = groupcounts(T.Alpha)
[~, last] = unique(T.Alpha, 'last')
T.Ticket(last(n>1))
Using the "new and shiny" groupcounts.

  0 Comments

Sign in to comment.


Sonima
Sonima on 9 Aug 2019
T.Ticket(groupcounts(T.Alpha)>1)

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by