필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by