Using polyfit for linear regression
조회 수: 12 (최근 30일)
이전 댓글 표시
Hi guys, how do i get linear regression (p) of this X1 and Y1 values using polyfit?
I try but the X1 and Y1 keep changes back, expected i get like this graph in help window
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/374596/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/374601/image.png)
댓글 수: 2
답변 (1개)
Bjorn Gustavsson
2020년 10월 8일
Your code looks OK. Your problem might be that you expect a result identical to the figure from the documentation.
However, you ask for a linear fit in your call to polyfit - note the difference between your call and the call in the documentation!
your call:
p = polyfit(x,y,1);
Call in documentation:
p = polyfit(x,y,7);
You ask for a first-order polynomial, the call from the documentation is for a 7-order polynomial. That's the difference.
HTH
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!