Finding a distance between two cities with matlab codes
3 ビュー (過去 30 日間)
古いコメントを表示
I have a lattitude and longitude information of two cities, and i want to find the distance between them, how can i do it with matlab? i made with pdist command which computes the euclidean distance, but after i noticed that it would be wrong because of the shape of the world.
0 件のコメント
採用された回答
Andrei Bobrov
2012 年 8 月 6 日
編集済み: Andrei Bobrov
2012 年 8 月 6 日
use Mapping Toolbox
eg:
citys1 - lattitude and longitude in degrees of Saint-Petersburg;
citys2 - lattitude and longitude in degrees of Vladivostok;
citys1 = [59.946071,30.363464];
citys2 = [43.126045,131.904602];
a = distance(citys1,citys2);
out = deg2km(a);
without Mapping Toolbox
R = 6371; % km - radius of the Earth;
A = abs(citys1(2)-citys2(2));
c = 90-citys1(1);
b = 90-citys2(1);
a2 = acos(cosd(b)*cosd(c) + sind(b)*sind(c)*cosd(A));
out2 = R*a2;
0 件のコメント
その他の回答 (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!