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?

回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 7 月 3 日
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

この質問は閉じられています。

質問済み:

Nik
2014 年 7 月 3 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by