Distance of Latlon based locations in an array

4 ビュー (過去 30 日間)
Rakibul Islam Rony
Rakibul Islam Rony 2019 年 3 月 20 日
コメント済み: darova 2019 年 5 月 3 日
Hi,
I have a matrix. 1st column have latt and second with lon. Now, how do i calculate the distances between each other?
35.3333 25.10555
35.33361111 25.07666
35.3316 25.157
35.33861 25.1325
35.3375 25.136
35.335 25.134166
I have tried distance function, it works between two points. Soon try to select it from the array, it shows errors.
I tired: [arclen,az] = distance(Locations (1,:), Locations (2,:)), Locations is the name of my matrix.
The erros message:
Undefined function 'real' for input arguments of type 'table'.
Error in parseDistAzInputs (line 104)
lat1 = real(lat1);
Error in distance (line 95)
units, insize, useAngularDistance] = parseDistAzInputs(varargin{:});
Can you please help me to write the code to find distance between each other fo these points?
  2 件のコメント
KSSV
KSSV 2019 年 3 月 20 日
What you need is pdist2. Read about it.
Rakibul Islam Rony
Rakibul Islam Rony 2019 年 5 月 3 日
Thanks

サインインしてコメントする。

採用された回答

Martin Vatshelle
Martin Vatshelle 2019 年 3 月 20 日
編集済み: Martin Vatshelle 2019 年 3 月 20 日
You should not use normal distance for lat-lon points. The reason is that for latitude 1 degree is approximately the same distance (around 110 km). While 1 degree of longitude is different depending on how far north you are.
There are many functions out there, e.g.
Then you need to loop over all pairs somehow, and call this function
Below is a sample code
% make points as cell array
points = {[35.3333 25.10555];
[35.33361111 25.07666];
[35.3316 25.157];
[35.33861 25.1325];
[35.3375 25.136];
[35.335 25.134166]};
% generate all pairs
pairs = nchoosek(1:length(lat),2);
p1 = points(pairs(:,1),:);
p2 = points(pairs(:,2),:);
% compute distance
dist = cellfun(@lldistkm,p1,p2);
  2 件のコメント
Rakibul Islam Rony
Rakibul Islam Rony 2019 年 5 月 3 日
Thank U, the idea helped.
darova
darova 2019 年 5 月 3 日
accept the answer

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by