how to use histogram(data, num_bins)?

4 次查看(过去 30 天)
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!

采纳的回答

the cyclist
the cyclist 2016-4-14
编辑:the cyclist 2016-4-14

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 个评论
59morgan
59morgan 2016-4-14
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 2016-4-14
"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.)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by