how to use histogram(data, num_bins)?

3 visualizzazioni (ultimi 30 giorni)
59morgan
59morgan il 14 Apr 2016
Commentato: the cyclist il 14 Apr 2016
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!

Risposta accettata

the cyclist
the cyclist il 14 Apr 2016
Modificato: the cyclist il 14 Apr 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 Commenti
59morgan
59morgan il 14 Apr 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?
the cyclist
the cyclist il 14 Apr 2016
"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.)

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by