フィルターのクリア

Obtaining line equation having multiple points

20 ビュー (過去 30 日間)
Mostafa Moradi
Mostafa Moradi 2021 年 2 月 28 日
コメント済み: Star Strider 2021 年 2 月 28 日
Hi everyone,is there a way to obtain line equation having multiple points (around seven points) of that line as a 2*7 matrix?

回答 (1 件)

Star Strider
Star Strider 2021 年 2 月 28 日
The polyfit (and polyval) functions may be what you want.
There are other options, however these are likely the easiest to use.
  2 件のコメント
Mostafa Moradi
Mostafa Moradi 2021 年 2 月 28 日
this is the data set I have,
y= [0 1 3 5 7 8 9 10]; %distance from sea bank
H= [0 1 1.5 3 3.5 3.2 2 0]; %depth
u= [0 0.1 0.12 0.2 0.25 0.3 0.15 0]; %velocity
how do I apply the above function to get the (y,H) and (y,u) lines equation?
Star Strider
Star Strider 2021 年 2 月 28 日
Try this:
y = [0 1 3 5 7 8 9 10]; %distance from sea bank
H = [0 1 1.5 3 3.5 3.2 2 0]; %depth
u = [0 0.1 0.12 0.2 0.25 0.3 0.15 0]; %velocity
ByH = polyfit(y,H,1);
fit_yH = polyval(ByH,y);
Byu = polyfit(y,u,1);
fit_yu = polyval(Byu,y);
figure
plot(y, H, 'pb')
hold on
plot(y, u, 'pg')
plot(y, fit_yH, '-b')
plot(y, fit_yu, '-g')
hold off
grid
xlabel('y')
ylabel('Amplitude')
legend('H','u','Fit_H','Fit_u', 'Location','NW')
These will provied a linear fit to both dependent data vectors with respect to ‘y’. For polynomial fits of greater (integer) degrees, see the documentation I linked to earlier.
Change other parts of my code to get the results you want.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by