Help with the unique function

2 ビュー (過去 30 日間)
Temi
Temi 2017 年 1 月 13 日
コメント済み: Temi 2017 年 1 月 14 日
The unique function fails to sort the following redundancy;
K>> b
b = [15.0000 15.0000 15.0000 -5.0000 15.0000]
K>> unique(b)
ans = -5.0000 15.0000 15.0000 15.0000 15.0000
but when the vector is made up of integers:
a = [15 15 15 15 -5 15]
K>> unique(ans)
ans = -5 15
How can I solve this problem?

採用された回答

Guillaume
Guillaume 2017 年 1 月 13 日
If you look at the output of
b - 15
You'll see that some (or all) these 15.0000 are not actually 15.0000 but something very close to it but different from each other.
The solution: use uniquetol:
uniquetol(b); %you can specify the tolerance as well.
  1 件のコメント
Temi
Temi 2017 年 1 月 14 日
thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by