フィルターのクリア

Could someone explain this straight line function?

2 ビュー (過去 30 日間)
Jack Rimmer
Jack Rimmer 2021 年 1 月 14 日
回答済み: David Hill 2021 年 1 月 14 日
I found this bit of code in another help thread:
func = @(x)a(1) + (a(2)-b(2))/(a(1)-b(1))*(x-a(1));
I have gotten it to work in matlab fine but I dont actually understand what it is doing on a mathimatical level.
Could someone explain so I solve some errors im having with similar functions?
Thanks

採用された回答

Stephan Ciobanu
Stephan Ciobanu 2021 年 1 月 14 日
Hi!
a(1) % extracts the first element of array a
a(2) % extracts the second element of array a
if a is an array: with
and b, similarly, with
func is:

その他の回答 (1 件)

David Hill
David Hill 2021 年 1 月 14 日
It is point-slope form of a line. If the points are a=[x2, y2] and b=[x1, y1], then:
m=(a(2)-b(2))/(a(1)-b(1));%slope
func =@(x) m*(x-a(1))+a(2);%above equation seems to be wrong, should be +a(2)
func =@(x) m*(x-b(1))+b(2);%same thing just using other point

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by