Is there any method for implementing the UNIQUE function without sorting my array in MATLAB?
6 ビュー (過去 30 日間)
古いコメントを表示
When I execute the following code in MATLAB
x = [5 4 4 6 1];
unique(x)
I observe the following output
ans =
1 4 5 6
However, I would like to eliminate duplicate values without sorting values by ascending values.
採用された回答
MathWorks Support Team
2012 年 4 月 10 日
This enhancement has been incorporated in Release 2012a (R2012a). For previous product releases, read below for any possible workarounds:
The ability to eliminate duplicates from an array without sorting is not available in MATLAB.
To work around this behavior, the indices returned by UNIQUE can be used to retain the order in the returned matrix.
x = [5 4 4 6 1];
[b,i,j]=unique(x, 'first')
b =
1 4 5 6
i =
5 3 1 4
j =
3 2 2 4 1
x(sort(i))
ans =
5 4 6 1
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!