フィルターのクリア

Calculate the distance between a point and all the others

3 ビュー (過去 30 日間)
Marwen Tarhouni
Marwen Tarhouni 2016 年 11 月 30 日
編集済み: Guillaume 2016 年 11 月 30 日
Hi, I try to calculate the distance between a point and all the others. for exemple A(-20,90) B(-24,50) C(-23,90) D(-13,50) E(50,16)
I want to calculate the distance between (A and B) & (A and C) &(A and D) & (A and E)
also (B and A) & (B and C) &(B and D) & (B and E)
do you have an idea ?
x1= -20;
y1=90;
x2=-24;
y2=50;
x3=-23;
y3=90;
x4=-13;
y4=59;
x5= 50;
y6=16;
i=5;
% for while
while i<=4
i=i-1;
distance = sqrt((xi-x1)^2+(yi-y1)^2); ------------------> error distance???
end
Thanks
  1 件のコメント
Guillaume
Guillaume 2016 年 11 月 30 日
編集済み: Guillaume 2016 年 11 月 30 日
Where have you seen that matlab would magically understand that the i in the variable name xi is supposed to be substituted by the actual value of the variable i in order to make a new variable name?
There is no point in telling you how to calculate the distance if you don't even know how to index in matlab. Please, go through the getting started tutorial.

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

採用された回答

Guillaume
Guillaume 2016 年 11 月 30 日
See comment to question. You need to learn matlab first.
In R2016b, this is very straightforward:
points = [-20, 90;
-24, 50;
-23, 90;
-13, 50;
50, 16];
distance = hypot(points(:, 1) - points(1, 1), points(:, 2) - points(1, 2)) %distances to 1st point

その他の回答 (1 件)

Torsten
Torsten 2016 年 11 月 30 日
Use "pdist".
Best wishes
Torsten.
  1 件のコメント
Guillaume
Guillaume 2016 年 11 月 30 日
Well, the function to use for the distance is the least of the OP problem. Learning matlab would be required first.

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by