In time: I found that the values in my Z matrix is in fact the 2-norm (or Euclidean distance) between all my 399 points. But how can I convert them to km? Only with haversine formula?
How to calculate the Euclidean distance beetwen all points of Latitude Longitude pairs?
조회 수: 31 (최근 30일)
이전 댓글 표시
I have a 399 cities array with LON LAT coordinates (first column for the Longitudes), like the picture below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286085/image.png)
How can I calculate the 399x399 matrix with all distances between this 399 cities?
I used pdist and squareform but the result are small number. Am I correct?
D = pdist(XY);
Z = squareform(D);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286086/image.png)
For example, the two first points (-50.3125 -23.3005; -48.9918 -24.6617) have a Euclidean distance between them of 216 km (see picture below).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/286087/image.png)
Thank you!
댓글 수: 2
Geoff Hayes
2020년 4월 21일
David - yes, Haversine is one way to get the distance between two latitude and longitude points. The Vincenty algorithm (see https://www.mathworks.com/matlabcentral/fileexchange/5379-geodetic-distance-on-wgs84-earth-ellipsoid) is another..
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!