Keep getting error message for polyfit

2 Ansichten (letzte 30 Tage)
Sarah Gilliam
Sarah Gilliam am 11 Dez. 2020
Beantwortet: Image Analyst am 12 Dez. 2020
I'm following a tutorial for an example out of a textbook, I've copied the instructors code exactly but keep getting an error message
My code:
x = 0:0.3:1.8;
y = [.5 .6 .8 1.3 2 3.2 4.8];
plot(x, y, 'b-*')
f = fit(x',y', 'poly2');
error message:
Check for missing argument or incorrect argument data type in call to function 'fit'.
Error in Week_9 (line 6)
f = fit(x',y', 'poly2');
I can't find the error in my code
  2 Kommentare
Walter Roberson
Walter Roberson am 11 Dez. 2020
Do you have the Curve Fitting Toolbox licensed and installed?
dpb
dpb am 12 Dez. 2020
What does
which -all fit
return?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 12 Dez. 2020
Try polyfit() and polyval()
x = 0:0.3:1.8;
y = [.5 .6 .8 1.3 2 3.2 4.8];
plot(x, y, 'b-*', 'LineWidth', 5)
coefficients = polyfit(x(:),y(:), 3);
f = polyval(coefficients, x);
hold on;
plot(x, f, 'ro-', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
legend('y', 'f');

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by