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 件のコメント

Mathieu NOE
Mathieu NOE 2022 年 2 月 7 日
HI
have you tried with 1st order polynomial (using polyfit) ?
Image Analyst
Image Analyst 2022 年 2 月 7 日
@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 日

0 投票

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

Community Treasure Hunt

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

Start Hunting!

Translated by