shaded confidence interval plotting with shade area (patch)

21 views (last 30 days)
Hello,
I'm trying to plot the shadow area between the confidence interval with the line in the middle. I've tried a few approaches, but each time I'm getting the same results (plot image). I've attached a data and code below. Please help, I don't know why I have this problem. I've read similar tags, and tried to adhere to the solutions, but it seems that doesn't work for my case.
% Using Matlab - calculations of confidence interval
pd = fitdist(X,'Normal')
ci = paramci(pd)
a4=ci(1,1)/pd.mu;
b4=ci(2,1)/pd.mu;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=X.*a4;
y=X.*b4;
Ymax=y;
Ymin=x;
figure
plot(time,Ymax)
hold on
plot(time,Ymin)
line([time(end) time(end)],[Ymin(end),Ymax(end)])
line([time(2) time(2)],[Ymin(1),Ymax(1)])
patch([time fliplr(time)], [Ymax fliplr(Ymin)], 'g')

Accepted Answer

Star Strider
Star Strider on 7 Apr 2021
The data in ‘data-confidence interval.xls’ are read in as column vectors, so fliplr simply flips a column vector, and accomplishes nothing. It is necessary to vertically concatenate the vectors with their flipped versons.
Try this instead:
patch([time; flipud(time)], [Ymax; flipud(Ymin)], 'g')
producing:
.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!