Remove duplicates and original also
古いコメントを表示
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. for example:
A = 1,2,2,2,3,3,3,4,5; B = unique(A); B = 1,2,3,4,5
what i'm actually looking for is B = 1,4,5 where even the first instance of repeating elements is taken out. is this possible?
Thanks
採用された回答
その他の回答 (2 件)
Azzi Abdelmalek
2016 年 8 月 5 日
A = [1,2,2,2,3,3,3,4,5]
b=unique(A,'stable')
c=hist(A,b)
B=b(c==1)
2 件のコメント
Declan Bourke
2016 年 8 月 5 日
This does not work if A is not sorted into order:
>> A = [3,3,3,5,1,4,2,2,2,2];
>> b=unique(A,'stable');
>> c=hist(A,b)
Error using histc
Edge vector must be monotonically non-decreasing.
Error in hist (line 92)
nn = histc(y,edges,1);
Although beginners might think that the 'stable' makes a difference, this then provides a non-monotonic sequence to histc, which is not allowed.
Azzi Abdelmalek
2016 年 8 月 5 日
編集済み: Azzi Abdelmalek
2016 年 8 月 5 日
[ii,jj,kk]=unique(A)
out=ii(accumarray(kk,1)==1)
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!