Can't plot polyfit

4 次查看(过去 30 天)
Ander Azpitarte
Ander Azpitarte 2020-10-19
评论: Adam Danz 2020-10-19
REGRE_FG=polyfit(FGS(86:99),FGS(86:99))
figure
plot(REGRE_FG)
I have this code where
[FGEl(86:99),FGS(86:99)]
ans =
0.0011 80.3471
0.0011 81.5330
0.0012 82.7614
0.0012 83.9897
0.0012 85.1755
0.0012 86.3615
0.0014 92.1641
0.0015 97.8820
0.0016 103.5999
0.0018 109.3179
0.0019 115.0781
0.0021 120.7112
0.0022 126.3021
0.0024 131.8082
However, MATLAB says:
Not enough input arguments.
Error in polyfit (line 56)
V(:,n+1) = ones(length(x),1,class(x));
Does anyone know how to solve this? Also, does anyone know how to write the polyfit equation?

采纳的回答

Star Strider
Star Strider 2020-10-19
编辑:Star Strider 2020-10-19
The polyfit function also needs to know what degree of polynomial you want to fit:
p = polyfit(x,y,n)
where ‘n’ is the degree (1=linear, 2=quadratic, etc.).
Also, in order to plot it, you will need to evaluate it first with the polyval function.
EDIT — (19 Oct 2020 at 198:10)
Since your data are linearly related, the full code would go something like this —
REGRE_FG=polyfit(FGEl(86:99),FGS(86:99),1);
REGRE_FG_fit = polyval(REGRE_FG,FGEl(86:99));
figure
plot(FGEl(86:99),FGS(86:99), 'p')
hold on
plot(FGEl(86:99), REGRE_FG_fit, 'r')
hold off
grid
xlabel('FGEl')
ylabel('FGS')
.
  1 个评论
Adam Danz
Adam Danz 2020-10-19
refline() is another way of plotting the regression line, too (example), although it doesn't have an option to plot the error estimates like polyval does.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by