Help with basic fitting

조회 수: 1 (최근 30일)
aurc89
aurc89 2014년 2월 23일
댓글: Image Analyst 2018년 9월 25일
Hello,I would like to fit a curve with a line and retrieve slope and intercept of this linear fit. Let x and y be the vectors which define the curve, which is already similar to a line; I plot x vs y, then from the plot window I select Tools --> Basic fitting --> Linear fit, then I press 'Show equation' so that from the expression y=mx + q I retrieve both the slope m and the intercept q. The problem is that I want to obtain immediatly m and q from the Matlab code, without doing it manually as discussed above. How can I do this ? Thanks

채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 23일
편집: Mischa Kim 2014년 2월 23일
Try
[p,S] = polyfit(x,y,1)
The two elements of p are the coefficients m and q you are looking for.
  댓글 수: 2
Andrea Gómez Montoya
Andrea Gómez Montoya 2018년 9월 25일
What is S on the answer?
Image Analyst
Image Analyst 2018년 9월 25일
It's explained in the help for polyfit().

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 2월 23일
for what it's worth, I've attached a demo of polyfit.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by