Shade area between confidence intervals (ecdf)

조회 수: 4 (최근 30일)
Panos
Panos 2013년 3월 24일
I am using the ecdf command to plot empirical cdfs with their associated confidence intervals. I want to fill in/shade the confidence interval area.
This is the code i have used for the confidence intervals:
data1 = xlsread('File1.xlsx');
[F,X,Flo1,Fup1] = ecdf(data1);
plot(X,F,'LineWidth',2);
hold on;
plot(X,Flo1,'r-');
plot(X,Fup1,'r-');
hold off
and this is the code using shadedplot:
ha=shadedplot(X,Flo1',Fup1', [0.2 0.7 0.7], 'g');
I could not get it to work however. It still gives me the confidence intervals but they are not shaded in. Any help will be greatly appreciated (I'm a beginner in Matlab!)

채택된 답변

the cyclist
the cyclist 2013년 3월 24일
편집: the cyclist 2013년 3월 24일
Do you know if the shadedplot() command you are using is this one from the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/18738-shaded-area-plot?
It is a little difficult to help you debug this, because we don't have your data (and we don't have your function unless we download it).
I can suggest a few things, though. It looks like shadedplot() is supposed to plot the lines as well as the shaded area. But you are also plotting the lines with separate plot commands. Do you get the lines from shadedplot if you do not do the other plot commands?
You could try to see if you can post a small sample of your data that still exhibits the problem. Then, we can at least to replicate the problem (if people are willing to download the FEX code). This simplification may actually also help you see what is causing the problem.
Another thing I would suggest is using debug mode to step into the code and see if you can tell why the shading isn't working. There are detailed instructions on how to do that here: http://www.mathworks.com/help/matlab/debugging-code.html. (This is something that is good for any beginner to learn!)
  댓글 수: 3
the cyclist
the cyclist 2013년 3월 25일
I found the problem. Your Flo and Fup variables have NaN's in them, and apparently shadedplot() cannot handle that. I found that the following worked for the shading:
shadedplot(X(2:end-1),Flo(2:end-1)',Fup(2:end-1)',[.5 .5 .5],'r');
because the NaNs are in the first and last position of Flo and Fup. To make a more general solution, you would need to identify and remove the NaNs in a more general way. The isnan() command might be handy for you to do that.
Panos
Panos 2013년 3월 27일
the cyclist, thank you very much for the help! it works fine now!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by