Linear Fitting starting from a value
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi everyone!
I need to fit these data [100 90 80 70 50 45 40 43 42 40 35] whom are distanced by 10 seconds.
The problem is that I would fit these data starting from the first value (100) in order to understand the slope of the line.
Is it possible?
Thanks!
댓글 수: 0
채택된 답변
Torsten
2022년 10월 10일
편집: Torsten
2022년 10월 10일
Sure. Use
l(x) = a*x + 100
as model function and fit the parameter a.
xdata = ...; % your xdata as column vector
ydata = ...; % your ydata as column vector
a = xdata\(ydata-100)
But starting from a certain x-value, the slope seems to change. You should separate the fit into two parts:
l1(x) = a*x + 100 0 <= x<= x1
l2(x) = b*x + [(a-b)*x1 + 100] x1 <= x <= x(end)
댓글 수: 0
추가 답변 (1개)
Hiro Yoshino
2022년 10월 10일
편집: Hiro Yoshino
2022년 10월 10일
refline is the easiest way to achieve that.
y = [100 90 80 70 50 45 40 43 42 40 35];
x = 0:10:10*(length(y)-1);
plot(x,y,'o');
refline
if you want to know the coefficients:
p = polyfit(x,y,1)
polyfit for reference.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!