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!