Calculate distance between XY coordinates
317 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Naruto
am 8 Nov. 2020
Kommentiert: Naruto
am 11 Nov. 2020
How do we calculcate one xy coordinate against other xy coordinates in a 1000x2 matrix?
0 Kommentare
Akzeptierte Antwort
Sreeranj Jayadevan
am 11 Nov. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!