Problem plotting with bar() instead of hist()

1 回表示 (過去 30 日間)
John
John 2013 年 1 月 21 日
Hi,
I use this code to overlay a CDf plot on a histogram. Note the histogram data in binned according to bin centers.
bin = 110:10:220;
[y2,x2] = ecdf(y);
[y1,x1] = hist(y,bin);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
However, I need to bin the data using bin edges instead. I have tried using the histc function but cannot get the plot to display. You have to use the bar function in order to plot the histc data, but the bar function can only have 1 output argument. Could anybody help me out with the correct syntax for the plotyy fucntion now that I'm using the bar() instead of hist()?
Thank you
bin = 110:10:250;
histc(data,bin);
binneddata = ans / length(data)
[y2,x2] = ecdf(data);
[y1,x1] = bar(binneddata);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
  3 件のコメント
John
John 2013 年 1 月 21 日
I don't, I'm just not sure what the output should be for bar(), I tried the code below but it is incorrect.
[y2,x2] = ecdf(data);
[y1] = bar(binneddata);
plotyy(x1,y1,y2,@(x,y)bar(x,y,1,'c'),'stairs')
Thanks
John
John 2013 年 1 月 22 日
編集済み: John 2013 年 1 月 22 日
Hello Walter,
If you have minute would be in a position to advise me on the correct syntax for the plot function above?
Thank you

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 1 月 22 日
bin = 110:10:250;
binneddata = histc(data,bin) ./ length(data);
[y2,x2] = ecdf(data);
plotyy(bin, binneddata, x2, y2, @(x,y)bar(x,y,1,'c'), 'stairs')
  1 件のコメント
John
John 2013 年 1 月 22 日
Thank you for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by