Removing duplicate strings from an array and original
58 ビュー (過去 30 日間)
古いコメントを表示
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
採用された回答
Stephen23
2016 年 8 月 8 日
編集済み: Stephen23
2016 年 8 月 8 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!