How to detect the repetition of any number in a array?

3 ビュー (過去 30 日間)
Arnab Pal
Arnab Pal 2017 年 8 月 21 日
コメント済み: Prasobhkumar P. P. 2020 年 7 月 27 日
Say a=[4 5 8 9 4], How to detect this set has repeated numbers? I do not want to know the number, I just want to know that "a set has repeated numbers or not"

採用された回答

KSSV
KSSV 2017 年 8 月 21 日
Check unique. If the length of your array and length of unique are not same it has repeated numbers.
a=[4 5 8 9 4] ;
b = unique(a) ;
if length(a)~=length(b)
fprintf('array has repeated numbers\n')
else
fprintf('array has no repeated numbers\n')
end
  1 件のコメント
Prasobhkumar P. P.
Prasobhkumar P. P. 2020 年 7 月 27 日
Saved lots of hours of mine, thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by