필터 지우기
필터 지우기

Curve Fitting

조회 수: 22 (최근 30일)
Nathan
Nathan 2012년 6월 5일
댓글: Ali 2018년 11월 21일
I've been trying to fit different series/methods to a certain set of data. I have a polynomial fitted to the data: P = polyfit(x,y,3)
but I cannot get the fourier or the gaussian commands to work: p = fit(x,y,'fourier3)
Can someone help me?
Thanks

답변 (4개)

Teja Muppirala
Teja Muppirala 2012년 6월 6일
As proecsm points out, your data needs to be made into columns. Like this:
x = 1:1000; %Row vector
y = sin(0.01*x) + cos(0.03*x) + 0.1*randn(size(x)); %Row vector
F = fit(x(:),y(:),'fourier3') %Use (:) to turn it into a column
plot(x,y)
hold on
plot(F)
Also, are you aware of the Curve Fitting Tool GUI?
cftool
This makes it easier to try out different fits interactively (for both curves and surfaces), and you can automatically generate MATLAB code from your results.

Brandon Armstrong
Brandon Armstrong 2012년 6월 5일
Does not work mean you get an error, or just that the fit is very bad? If it is not fitting properly you can try giving some initial guesses and and upper and lower bounds for your coefficients using 'fitoptions'.

Nathan
Nathan 2012년 6월 5일
I'm getting these errors whenever I try to use other fits besides polyfit
Error using fit>iFit (line 129) X must be a matrix with one or two columns.
Error in fit (line 109) [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in TestProcedure_2 (line 34) [p] = fit(x,y,'fourier4');
  댓글 수: 1
Ali
Ali 2018년 11월 21일
correct form: fit(x(:),y(:),'fourier4')
(:) are used to turn it into a column

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


bym
bym 2012년 6월 5일
polyfit()
will work with both row-oriented or column-oriented data, whereas the documentation specifically mentions columns for
fit()
I don't have the curve fitting toolbox to test this.

카테고리

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