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개)

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