Keep getting error message for polyfit

조회 수: 7 (최근 30일)
Sarah Gilliam
Sarah Gilliam 2020년 12월 11일
답변: Image Analyst 2020년 12월 12일
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
Walter Roberson
Walter Roberson 2020년 12월 11일
Do you have the Curve Fitting Toolbox licensed and installed?
dpb
dpb 2020년 12월 12일
What does
which -all fit
return?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2020년 12월 12일
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');

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by