How do I use the results of the polyfit command for the rest of my code?

Depending on a single variable 'x', I get a 2nd degree polynomial equation.I needed the values of the coefficients of this polynomial equation. I got those values using the 'polyfit' command. Now i need to use these values in the rest of the procedure. I think this procedure can be automated. How do i use the output of the 'polyfit' command, as input for the rest of the procedure?

Réponses (1)

Useully you would like to use the parameters of the fit to obtained fitted values. Something along these lines, perhaps?
x = 1:10
y = 2 * x - 8
ynoise = y + randn(size(y)) % y-values with noise
p = polyfit(x,ynoise,1)
yfit = polyval(p,x) % fitted Y values
plot(x,y,'bo',x,ynoise,'rs', x,yfit,'r.-')
legend({'real','noisy','fitted'})
res = yfit - y % residuals

Cette question est clôturée.

Question posée :

Nik
le 3 Juil 2014

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by