how can I find the distance between succesive points in a big matrix

1 ビュー (過去 30 日間)
DAMILOLA BALOGUN 2019 年 10 月 27 日
コメント済み: DAMILOLA BALOGUN 2019 年 10 月 27 日
Hi everyone, I have a big data and i want to find the distances between succesive points in the data, how can this be done. I can find the distance between points easily with the pythagoras theorem d=sqrt((x2-x1)^2+(y2-y1)^2) but this is time wasting for a big data. I want to find distance between row 1 and row 2, row 3 and row 4, and so on
This is just 6 rows from my 44 X2 matrix.
x y
-22.7571 19.2166
-21.7591 20.2866
-21.4567 17.9427
-20.4284 19.0637
-20.0958 16.7197
-19.1885 17.7389
Thanks.

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

採用された回答

dpb 2019 年 10 月 27 日
d=diff(xy); % presume 2D array is xy
d=hypot(d(:,1),d(:,2));
pdist may be as fast even though computes all pairwise values, but I didn't test it.

1 件のコメント

DAMILOLA BALOGUN 2019 年 10 月 27 日
O "wow" you saved a life.
Thanks a lot

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

Community Treasure Hunt

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

Start Hunting!

Translated by