How to detect the repetition of any number in a array?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!