필터 지우기
필터 지우기

Find non unique string in a table

조회 수: 2 (최근 30일)
Sonima
Sonima 2019년 8월 6일
답변: Sonima 2019년 8월 9일
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?

채택된 답변

Adam Danz
Adam Danz 2019년 8월 6일
편집: Adam Danz 2019년 8월 8일
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)

추가 답변 (2개)

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

Sonima
Sonima 2019년 8월 9일
T.Ticket(groupcounts(T.Alpha)>1)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by