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!