different cdf plot produced by 2 different code

1 回表示 (過去 30 日間)
John
John 2013 年 1 月 23 日
Hello,
I created 2 plots below using the same data but different code. Could anybody explain to me why the cdf plot (red line) in the top plot does not match the bottom plot.
The bottom plot is the correct plot (I think).
binneddata = histc(data,bin) ./ length(data);
[y2,x2] = ecdf(data);
plotyy(bin, binneddata, x2, y2, @(x,y)bar(x,y,1,'c'), 'stairs')
[y2,x2] = ecdf(data);
[y1,x1] = hist(data);
plotyy(x1,y1,x2,y2,@(x,y)bar(x,y,1,'c'),'stairs')
  1 件のコメント
John
John 2013 年 1 月 23 日
編集済み: John 2013 年 1 月 24 日
bump bump

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

回答 (1 件)

Tom Lane
Tom Lane 2013 年 1 月 24 日
When I try your commands after
rng(0)
data = 150 + 10*randn(200,1);
bin = 100:10:250;
I get the same cdf curve in the two figures. If you type
which stairs
do you see the one that is part of MATLAB or is there another one hanging around?
  2 件のコメント
John
John 2013 年 1 月 24 日
Hello Tom,
Thank you for your reply and the explanation.
My issue is that when you go to the 0.5 point on the cdf curve and come down to the x-axis, the value on the x-axis in not the same with both methods.
I tried it using your code and saw the same result. I presume it is as a result of the way the data is binned.But which returns the correct value?
I think the second method produces the correct graph.
But I prefer to bin the data according to the bin edges using histc() but overlaying a cdf on it appears to produce an incorrect graph.
What do you think?
Thanks
Tom Lane
Tom Lane 2013 年 1 月 25 日
If I run my three lines of code, then your code with a "figure(2)" inserted before the second plotting command, I see both plots having (x=149.6995,y=0.5) on the blue curve. They look this way by eye and they show these values if I turn on the data cursor.
Notice that the two y axes on the same figure share the same x axis. You did substantial customization of the display. Could any of this have caused the x ticks for blue curve not to display, and to be different from the ones for the histogram? That's my only idea. Perhaps you can provide more code to reproduce both figures exactly and illustrate the problem.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by