Maximum occurrence of a number

10 visualizaciones (últimos 30 días)
Bless
Bless el 11 de Feb. de 2013
I have a row vector and some of the elements may same. How to get the value which is maximum in numbers?
For Eg:
V=[1 2 3 4 1 1 1 2]
I want a resultant value from V which should result me '1'. Since 1 occurs 4 times(maximum) in this vector. How to do this in matlab??

Respuesta aceptada

Jos (10584)
Jos (10584) el 11 de Feb. de 2013
The value that occurs most is called the mode. See http://en.wikipedia.org/wiki/Mode_(statistics)
This function is available in MatLab:
a = [1 2 3 4 5 2 6 2]
mode(a)
% ans = 2

Más respuestas (1)

Jan
Jan el 11 de Feb. de 2013
Editada: Jan el 11 de Feb. de 2013
You can find such solutions by asking your favorite search engine, e.g.:
Asking for "Matlab maximum occurence of a number" is less successful, but one of the first hits forwards to "doc mode" also.
Please do not get me wrong: All Matlab related questions are welcome here (and only a tiny part is not worth to be answered), but it is more efficient for you and the answerers of this forum, if you try to find a solution by your own at first.

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by