I have array of 2500 elements.i would to find a number from this array which is maximum times in array and i don't know that number
1 次查看(过去 30 天)
显示 更早的评论
I have array of 2500 elements.i would to find a number from this array which is maximum times in array and i don't know that number
0 个评论
采纳的回答
Matthew Eicholtz
2012-11-5
I'm sure there is a one-liner that can solve your problem, but here is one option:
Let
A = randi(10,[2500 1]); % 2500x1 vector with all random integers <= 10
B = unique(A);
[~,j] = max(arrayfun(@(x) sum(A==x),B));
Then the value that appears the most in A is given by B(j).
更多回答(1 个)
另请参阅
类别
在 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!