Hello, I have a few points, and I need to approximate them with linear function that goes through zero. Any ideas?) Thank you in advance)

댓글 수: 3

HI
have you tried with 1st order polynomial (using polyfit) ?
@Mathieu NOE I was going to suggest the way Matt did it
x=0:5 + 3;
y = 1.5 * x + randn(size(x)) * 0.4 + 10;
slope = x(:) \ y(:);
yFitted = slope * x;
plot(x,y,'.',x,yFitted, 'MarkerSize', 20);
grid on;
Is there a way to get the offset to be zero with polyfit()?

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

 채택된 답변

Matt J
Matt J 2022년 2월 7일
편집: Matt J 2022년 2월 7일
Here's a simple example.
x=-5:5;
y=2*x+randn(size(x))*0.4;
slope=x(:)\y(:);
yapprox=slope*x;
plot(x,y,'o',x,yapprox);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2022년 2월 7일

댓글:

2022년 2월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by