Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Shade area between confidence intervals (ecdf)

Asked by Panos on 24 Mar 2013

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

0 Comments

Panos

Products

No products are associated with this question.

1 Answer

Answer by the cyclist on 24 Mar 2013
Edited by the cyclist on 24 Mar 2013
Accepted answer

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 Comments

Panos on 25 Mar 2013

thank you very much for your quick response.

yes, the shadedplot command i am using is the one in your link.

I tried the shadedplot command with and without the other plot commands, and it gives me the same result. My data is just a column vector, i post here below a sample of it with the code i used, with and without the other plot commands:

clear;clc;close all
x=[276,222,346.153,623.0769, 143.5294, 340,179,145,184.6154,256,380.7692,...
209.6154,168.8889,470,210,350,142,461.5385,538.4615,233.0769,168,220,423,...
150,152.7273,251.8519,317.3077,189.2308,285,300,230.7692,300,416.8421...
143.0769,438.4615,390,390,156.9231,266.7692,369.2,308,175.3,846,126.923...
241.1538,162,180,178,150,288.461,527.5,500,403.8462,432.6923,415.3846...
268,300,607,490,253.8462,184.6154,250,340.3846,310,257,390.3846,350];
%without other plot commands
[F,X,Flo,Fup] = ecdf(x);
shadedplot(X,Flo',Fup',[.5 .5 .5],'r');
hold off;
%with other plot commands
plot(X,Flo,'r-'); hold on;
plot(X,Fup,'r-'); hold on;
shadedplot(X,Flo',Fup',[.5 .5 .5],'r');
hold off;

thank you for the link on debug mode

the cyclist on 25 Mar 2013

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 on 27 Mar 2013

the cyclist, thank you very much for the help! it works fine now!

the cyclist

Contact us