Question regarding the calling of cfit coefficients
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
TPazz
el 28 de Nov. de 2023
Comentada: TPazz
el 28 de Nov. de 2023
I have used the 'fit' function to apply a power2 curve fit to some data. The cfit object is called fitobject. Shown below:
fitobject = fit(xdata, ydata, 'power2')
As a result I get three coefficients in the form y = ax^b + c.
I know the correct way to call the coefficients in a script is:
a = fitobject.a; b = fitobject.b; c = fitobject.c;
But if I call the following:
a = fitobject(1); b = fitobject(2); c = fitobject(3);
I get slightly different values of the coefficients. Could someone please explain where the values above come from, and thus why they differ. E.g why fitobject.a is not equal to fitobject(1) etc?
I have been scouring the internet and cannot find an explanation. I suspect it's something to do with the confidence bounds?
Many thanks!
0 comentarios
Respuesta aceptada
Steven Lord
el 28 de Nov. de 2023
The way you gave, asking for the a, b, and c properties of the cfit object named fitobject, is one way to get the coefficients. This documentation page lists another: use the coeffvalues function. You'd probably also want to call the coeffnames function as well.
The second syntax you gave does not extract any coefficients at all. It evaluates the fit for x = 1, x = 2, and x = 3 respectively. Adapting the example on that documentation page:
load census
curvefit = fit(cdate,pop,'poly3','normalize','on')
Let's get one of the coefficients.
curvefit.p1
Let's get all the coefficients and display them as a table.
N = coeffnames(curvefit)
V = coeffvalues(curvefit)
results = table(N, V.', 'VariableNames', ["Coefficient names", "Coefficient values"])
What's the value of the fitted curve for the year 1925?
pop1925 = curvefit(1925)
Does this look right compared to the fitted curve and the data?
plot(curvefit)
hold on
plot(cdate, pop, 'ko', 1925, pop1925, 'bd')
Más respuestas (0)
Ver también
Categorías
Más información sobre Fit Postprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
