Can't plot polyfit

5 Ansichten (letzte 30 Tage)
Ander Azpitarte
Ander Azpitarte am 19 Okt. 2020
Kommentiert: Adam Danz am 19 Okt. 2020
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?

Akzeptierte Antwort

Star Strider
Star Strider am 19 Okt. 2020
Bearbeitet: Star Strider am 19 Okt. 2020
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 Kommentar
Adam Danz
Adam Danz am 19 Okt. 2020
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by