Borrar filtros
Borrar filtros

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

71 visualizaciones (últimos 30 días)
Khadija
Khadija el 5 de Jul. de 2024 a las 18:07
Comentada: Star Strider el 14 de Jul. de 2024 a las 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.
  1 comentario
Image Analyst
Image Analyst el 5 de Jul. de 2024 a las 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:

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 5 de Jul. de 2024 a las 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 comentarios
Khadija
Khadija el 14 de Jul. de 2024 a las 0:41
Thank you very much for your patience!!
Star Strider
Star Strider el 14 de Jul. de 2024 a las 1:02
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by