Export residuals from curve fitting

조회 수: 69 (최근 30일)
Mohammed Hammad
Mohammed Hammad 2019년 7월 7일
댓글: Mohammed Hammad 2019년 7월 7일
Hi,
I am using the curve fitting toolbox on MATLAB_R2019a to create a (linear least square fit) by creating a (Polynomial fit with 1 degree).
I would like to export the residuals values to an array. I know I can acheive that manually from Fit >> Save to work space >> output.
But I have a loop around 1000 file so I would like to export residuals individually for each fit.
Any help is apprciated.

채택된 답변

Matt J
Matt J 2019년 7월 7일
편집: Matt J 2019년 7월 7일
Instead of using cftool, use the fit() command,
[fitobject,gof,output] = fit(x,y,'poly1','Weights', w);
residuals=output.residuals;
  댓글 수: 1
Mohammed Hammad
Mohammed Hammad 2019년 7월 7일
Thanks a lot, I achieved what I want by editing my curvefit code after generating it from the toolbox as you mentioned
[fitobject,gof,output] = fit( xData, yData, ft, opts );
then I got the residuals from:
residuals=output.residuals;

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

추가 답변 (1개)

Matt J
Matt J 2019년 7월 7일
편집: Matt J 2019년 7월 7일
For a simple 1 degree polynomial, why not just use polyfit?
p=polyfit(x,y,1);
residuals=polyval(p,x)-y;
  댓글 수: 4
Mohammed Hammad
Mohammed Hammad 2019년 7월 7일
cool, but I have weights, how can I insert them in the polyfit function. I used to do that using the curve fitting toolbox but here, I don't know how to do it
Matt J
Matt J 2019년 7월 7일
편집: Matt J 2019년 7월 7일
Unfortunately, you cannot do weighted fitting with polyfit, so I would recommend fit() as I mentioned in my other answer.

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

카테고리

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