I have a 1000 element vector. I want to know if it has got any of its 2 or more elements equal. Is there a command to check this?
1 回表示 (過去 30 日間)
古いコメントを表示
Seetha Rama Raju Sanapala
2015 年 6 月 2 日
回答済み: Titus Edelhofer
2015 年 6 月 2 日
I can write a program to check if any of the elements are identical. But wanted to know if there is a built in command and or function to check this?
0 件のコメント
採用された回答
Titus Edelhofer
2015 年 6 月 2 日
Hi,
the easiest is to use unique
x = [1 1 2 3];
if numel(x)~=numel(unique(x))
disp('There are repetitive elements');
end
Note though, that this is without tolerance, i.e., 1.0 ~= 1.000000000001. Use uniquetol if you need some tolerance.
Titus
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!