different cdf plot produced by 2 different code

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

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 CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by