Calculate distance between 2 points using array

5 ビュー (過去 30 日間)
Antonin Ponchon De Saint Andre
Antonin Ponchon De Saint Andre 2021 年 5 月 1 日
コメント済み: Matt J 2021 年 5 月 1 日
Hi, how can I find the distance between 2 points using this equation? eqn=sqrt{{X_{i+1}-X_{i}}^2+{{Y_{i+1}-Y_{i}}^2}};
I need to use a matrix that is defined by the user (it cannot be changed) so any coordinates can be entered.
numberOfCoord=input('Please Input the Number of Coordinates:');
if numberOfCoord < 4
disp (['Error']);
return
end
data = zeros(2, numberOfCoord);
for i= 1:1:numberOfCoord
data(1, i)=input('Please Enter X Coordinate:');
data (2, i)=input ('Please enter Y Coordinate:');
end
if i < 0
disp (['Error']);
return
end
any tips or help to solve this would be great thanks :))
  2 件のコメント
Turlough Hughes
Turlough Hughes 2021 年 5 月 1 日
This code requires atleast 4 points, are you looking for distances from a given point to every other point?
Antonin Ponchon De Saint Andre
Antonin Ponchon De Saint Andre 2021 年 5 月 1 日
it would be between each pair of corners (i.e. distance between point 1 & 2, 2 & 3, 3 & 4, 4 & 1 IF 4 points are entered in the code)

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

採用された回答

Matt J
Matt J 2021 年 5 月 1 日
編集済み: Matt J 2021 年 5 月 1 日
vecnorm( diff(data,1,2) , 2, 1)
  2 件のコメント
Antonin Ponchon De Saint Andre
Antonin Ponchon De Saint Andre 2021 年 5 月 1 日
worked smoothly cheers !
Matt J
Matt J 2021 年 5 月 1 日
I'm glad, but please Accept-click the answer to certify that it worked for you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEarth, Ocean, and Atmospheric Sciences についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by