フィルターのクリア

Removing duplicate strings from an array and original

58 ビュー (過去 30 日間)
Declan Bourke
Declan Bourke 2016 年 8 月 8 日
コメント済み: Declan Bourke 2016 年 8 月 8 日
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
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.
  1 件のコメント
Declan Bourke
Declan Bourke 2016 年 8 月 8 日
Thats working great, thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by