How to detect the repetition of any number in a array?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arnab Pal
am 21 Aug. 2017
Kommentiert: Prasobhkumar P. P.
am 27 Jul. 2020
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"
0 Kommentare
Akzeptierte Antwort
KSSV
am 21 Aug. 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
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!