Non-sequential Hist Bins

Hello,
I am trying to use non-sequential histogram bins with an empirical CDF displayed over the YY plot in MATLAB 2017a. By non-sequential histogram bins I mean 1870-1879, 1880-1889, 1890-1899, etc. Currerntly, my code looks like:
%bins = round(min(death),-1)-5:10:round(max(death),-1)+5;
bins = [1870 1879 1880 1889 1890 1899 1900];
[y1,x1] = hist(death,bins);
[y2,x2] = ecdf(death);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
Where I commented out the first line of code after realizing I was double counting some people's deaths that fall on even decade values (i.e. 1990, 1910, 1920, etc.) Thanks

回答 (1 件)

Star Strider
Star Strider 2017 年 12 月 20 日

0 投票

I would experiment with the histc (link) function instead. It allows you to define the bin ranges instead of the bin centres.

5 件のコメント

Guillaume
Guillaume 2017 年 12 月 20 日
Both hist and histc have long been deprecated. Since R2014b, histcounts is recommended instead of histc.
Steven Lord
Steven Lord 2017 年 12 月 20 日
And since the last line of code uses plotyy (also not recommended, in favor of yyaxis) to plot the histogram using stairs, using histogram with DisplayStyle 'stairs' may be a good replacement.
Star Strider
Star Strider 2017 年 12 月 20 日
Both true. However not everyone has R2014b or later. I am assuming ‘John’ is one.
Steven Lord
Steven Lord 2017 年 12 月 21 日
You are correct that not everyone is using release R2014b or later, but John's first sentence ends "in MATLAB 2017a" so yyaxis and histogram are both available.
Star Strider
Star Strider 2017 年 12 月 21 日
Noted.
I figured that since he is using hist, he would have seen the deprecation notice, and was using the deprecated versions for compatibility reasons.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

タグ

質問済み:

2017 年 12 月 20 日

コメント済み:

2017 年 12 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by