how to use histogram(data, num_bins)?

3 views (last 30 days)
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!

Accepted Answer

the cyclist
the cyclist on 14 Apr 2016
Edited: the cyclist on 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 Comments
59morgan
59morgan on 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 on 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.)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!