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

71 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2024-7-5,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')
.
  10 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by