MATLAB: Can’t plot polyfit

curve fittingpolyfit

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?

Best Answer

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')
.