# Hello, I would like to know how to draw a shaded region like this?

77 views (last 30 days)
Khadija on 5 Jul 2024 at 18:07
Commented: Star Strider on 14 Jul 2024 at 1:02
I am trying to estimate the parameters for a mathematical model, I managed to do it but there remains a problem of determining the confidence interval and drawing the shaded region which contains the majority of the data points.
Image Analyst on 5 Jul 2024 at 18:33
If you have any actual questions, then ask them and attach your data and code to read it in with the paperclip icon after you read this:

Star Strider on 5 Jul 2024 at 18:50
Perhaps something like this —
x = linspace(0, 5, 25).';
y = 5*exp(-0.5*x) + randn(size(x));
fcn = @(b,x) b(1).*exp(b(2).*x) + b(3);
B0 = randn(3,1);
mdl = fitnlm(x, y, fcn, B0)
mdl =
Nonlinear regression model: y ~ b1*exp(b2*x) + b3 Estimated Coefficients: Estimate SE tStat pValue ________ _______ _______ ________ b1 5.5856 1.9322 2.8908 0.008483 b2 -0.30843 0.24258 -1.2715 0.21684 b3 -1.3477 2.218 -0.6076 0.54968 Number of observations: 25, Error degrees of freedom: 22 Root Mean Squared Error: 0.997 R-Squared: 0.66, Adjusted R-Squared 0.629 F-statistic vs. constant model: 21.3, p-value = 7.13e-06
[ynew,yci] = predict(mdl, x);
figure
hp1 = plot(x, y, '.', 'DisplayName','Data');
hold on
hp2 = plot(x, ynew, '-r', 'DisplayName','Regression');
hp3 = plot(x, yci, '--r', 'DisplayName','95% CI');
hp4 = patch([x; flip(x)], [yci(:,1); flip(yci(:,2))], 'r', 'FaceAlpha',0.25, 'EdgeColor','none', 'DisplayName','Shaded Confidence Interval');
hold off
grid
xlabel('X')
ylabel('Y')
legend([hp1,hp2,hp3(1),hp4], 'Location','best')
.
Khadija on 14 Jul 2024 at 0:41
Thank you very much for your patience!!
Star Strider on 14 Jul 2024 at 1:02
As always, my pleasure!

### Categories

Find more on Get Started with Curve Fitting Toolbox 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!