calculate distance between XY pair

2 ビュー (過去 30 日間)
Boby S
Boby S 2019 年 6 月 26 日
回答済み: Pawan Sharma 2020 年 7 月 30 日
Hi
I want to calculate distance between XY points but as pair not all of them.
I used 'pdist' and 'pdist2' function but they calculate distance for all points.
I want to calculate point 1(xy) with point 2(xy) then point 2(xy) with point 3(xy) and go on (it is a part of recorded movments).
I think I will need to write a loop but I am not sure about proper function.
  3 件のコメント
Boby S
Boby S 2019 年 6 月 27 日
Hello
That is right.
infinity
infinity 2019 年 6 月 27 日
Hello,
So, I think the anwser below is what you want.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 26 日
sqrt(diff(x).^2 + diff(y).^2)

その他の回答 (1 件)

Pawan Sharma
Pawan Sharma 2020 年 7 月 30 日
You can use the method suggested by Walter in a forloop to get the required ansewer
A = [ 1 3; 2 4; 3 6]
distanceList = zeros(1,size(A,1)-1); % calculated distance will be stored here
for i = 1:size(A,1)-1
data1 = A(i,:);
data2 = A(i+1,:)
distance = sqrt(((data1(1)-data2(1))^2)+(data1(2)-data2(2))^2);
distanceList(i) = distance;
end

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by