how to use histogram(data, num_bins)?

I have a 8945x1 double array, and I want to view it's distribution, as a histogram
first try: histogram(data), here's what I get:
second try: using histogram(data, 20):
what am I doing wrong?
data is attached as an excel file if anybody cares to investigate
thanks!

 Respuesta aceptada

the cyclist
the cyclist el 14 de Abr. de 2016
Editada: the cyclist el 14 de Abr. de 2016

The reason is that you have a very sharply peaked histogram with a very long tail. The default binning, and your 20-bin option, just don't capture the range well. Try this:

figure
histogram(data,[0:0.1:5 Inf])
xlim([0 5])

I've defined the edges of the bins as a vector. The result looks like this:

2 comentarios

59morgan
59morgan el 14 de Abr. de 2016
hmmm. nice. so, this: [0:0.1:5 Inf] means, go from 0 to 5 in increments of .1 (giving me 50 bins?) and then positive infinity? what's going on with that?
and this: xlim([0 5]) is just setting the range of the x axis? shouldn't that happen automatically, given your bins?
"histogram(X,edges) sorts X into bins with the bin edges specified by the vector, edges. Each bin includes the left edge, but does not include the right edge, except for the last bin which includes both edges."
In your case,
histogram(data,[0:0.1:5])
would be fine. The Inf will affect whether the last "real" bin includes its right edge or not. (When I include the Inf, then I need to put in the xlim.)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Abr. de 2016

Comentada:

el 14 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by