필터 지우기
필터 지우기

Calculate distance between XY coordinates

조회 수: 150 (최근 30일)
Naruto
Naruto 2020년 11월 8일
댓글: Naruto 2020년 11월 11일
How do we calculcate one xy coordinate against other xy coordinates in a 1000x2 matrix?

채택된 답변

Sreeranj Jayadevan
Sreeranj Jayadevan 2020년 11월 11일
You can use the pdist function to calcluate pairwise distance between pairs of observations.
Suppose "Coords" is your 1000 by 2 matrix, then the following MATLAB code can give you the distance:
%%Calculate distance
loc_1=1;
loc_2=2;
Coord_1=Coords(loc_1,:); % The first coordinate
Coord_2=Coords(loc_2,:); % The second coordinate
pair=[Coord_1;Coord_2];
distance=pdist(pair,'euclidean');
"distance" will give you the euclidean distance between the first and second coordinates. You can loop through the coordinate locations (i.e loop through the "loc_i" variable) to find the distance between a particular coordinate and the rest of the coordinates.
Note: The same result can be achieved in multiple ways, eg: using norm,sqrt etc..

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by