Most populated range of floating point numbers in array
Mostrar comentarios más antiguos
histc can be used on a floating point array to find the bin with the largest number of elements. However these bins are fixed, and for a fixed width of bin, might not be optimal.
Example
a=[0 0.01 0.4 0.45 0.55 0.56 0.60]
histc(a,[0 0.5 1])
ans =
4 3 0
So the most frequent bin is [0, 0.5]. However, I am interested in a function that finds the range of at most 0.5 wide, with the most elements, so in this case [0.4, 0.6] which contains 5 elements. Does anybody know an elegant way of doing this?
Respuesta aceptada
Más respuestas (1)
Honglei Chen
el 8 de Sept. de 2014
You can just do
histc(a,[0 0.4 0.6 1])
if you know for sure you want the interval [0.4 0.6]. Otherwise, you can use hist
y = hist(a,[0 0.5 1])
which specifies the center
1 comentario
lvn
el 8 de Sept. de 2014
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!