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

3 vues (au cours des 30 derniers jours)
Arnab Pal
Arnab Pal le 21 Août 2017
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"

Réponse acceptée

KSSV
KSSV le 21 Août 2017
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by