Function to find the more recurrent number
古いコメントを表示
Hye, I have a matrix 1 by (a big number, like 1000), and I would like to extract the element of the matrix that appears most of the time.
Can you help me?
採用された回答
その他の回答 (3 件)
Walter Roberson
2011 年 8 月 8 日
Much more simple:
x = mode(Y);
5 件のコメント
Liber-T
2011 年 8 月 8 日
Walter Roberson
2011 年 8 月 8 日
You must have an earlier MATLAB. mode() has been part of MATLAB for several versions, but I would have to research to find out when it was introduced.
Paulo Silva
2011 年 8 月 8 日
the mode function was introduced in the Service Pack 3 of Release 14 back in Setember 2005, I think it's the first time I see it, thanks for bring it up Walter :)
Liber-T
2011 年 8 月 9 日
Liber-T
2011 年 8 月 9 日
Paulo Silva
2011 年 8 月 8 日
Another possible way
a=randi([1 20],1,1000);
u=unique(a);
[C,I]=max(arrayfun(@(x)sum(a==u(x)),1:numel(u)));
disp('The value that appears most times is:')
u(I)
disp('Number of times it appears:')
C
In case of having two values that appear the same number of times it will choose just one of them.
huda nawaf
2011 年 8 月 10 日
0 投票
hi, see it please,
X=[1 1 1 2 3 4 4 4 0]; >> v=mode(X) ??? No appropriate methods for function mode. . I need the mode which compute frequencies of appearing of number. thanks
カテゴリ
ヘルプ センター および File Exchange で Adaptive Control についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!