how to use histogram(data, num_bins)?

3 ビュー (過去 30 日間)
59morgan
59morgan 2016 年 4 月 14 日
コメント済み: the cyclist 2016 年 4 月 14 日
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 Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by