Dear all
I am trying to to a fit to simple polynomial function.
However, when I try to use 'poly1' as a fittype it gives: Unrecognized function or variable 'poly1'.
I am using the command form as in the library f = fit(x, y, 'poly1'), or f = fit(x, y, poly1) -nothing works
how is it possible? I though it should be in the library as written here:
thank you

답변 (1개)

Chunru
Chunru 2023년 5월 11일

0 개 추천

x = (0:0.2:5)';
y = 2*exp(-.2*x) + 0.5 * randn(size(x));
f = fit(x, y, 'poly1');
% check the path of fit
which fit
/MATLAB/toolbox/curvefit/curvefit/fit.m
plot(f, x, y)
% f = fit(x, y, poly1) % not working unless poly1='poly1';

댓글 수: 4

Igor
Igor 2023년 5월 11일
thank you very much for the answer.
I just dont understand why then f = fit(x, y, 'poly1') didnt work for me f = fit(x, y, 'poly1'); works
Torsten
Torsten 2023년 5월 11일
Did you name one of your MATLAB functions "fit.m". Then rename it.
What does
which fit
give as output ?
Do you have the curve fitting toolbox installed and licenced ?
Igor
Igor 2023년 5월 12일
Hi
thank you for answer, yes I actually names the script file as fit.m so that could cause problems.
I think I have curve fitting toolbow add.
What is the function of - which fit?
which fit
asks MATLAB to first search the workspace (and calling parameters, and any shared variables) to see whether the name fit is associated with a variable in scope, and if so then tells you that it is a variable. If fit is not found as a variable in scope, then MATLAB searches for functions named fit, and if one is found then MATLAB will tell you the path to the function that was found.
Note that the search will not necessarily find the same fit that a call to fit will resolve to. If the parameters to fit involve a class that defines a method named fit then which fit will not find that method. You can, however, ask for (for example)
which fit(x)
in which case MATLAB will search for the fit that would be called if a value with the same type as x were to be passed to fit

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

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품

태그

질문:

2023년 5월 11일

댓글:

2023년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by