Calculate distance resulting from an histogram and a specific point

2 ビュー (過去 30 日間)
Ricardo Duarte
Ricardo Duarte 2022 年 12 月 20 日
回答済み: Voss 2022 年 12 月 26 日
Dear all,
I have two matrices that represent longitude and latitude.
With those matrices I calculated an histogram and now I want to calculate the distance between each non zero bin and a specific point
I have the following code so far:
[N,C]=hist3([longitude, latitude],[50 50]);
figure; surf(C{1,1}',C{1,2}',N'); view(2);
However now I don't know how to proceed.
Thank you in advance

採用された回答

Voss
Voss 2022 年 12 月 26 日
load matrix
[N,C]=hist3([longitude, latitude],[50 50]);
figure
hist3([longitude, latitude],[50 50],'CDataMode','auto')
view(2)
% the distance between this point and the centers
% of the non-zero bins will be calculated:
P = [-17 34];
[x,y] = ndgrid(C{:});
idx = N > 0;
d = sqrt((x(idx)-P(1)).^2 + (y(idx)-P(2)).^2)
d = 10×1
5.9616 6.1132 9.3794 0.6432 9.0385 1.9591 11.6658 12.1413 9.8034 13.3336
Note that that's Euclidean distance (in degrees lat/lon); the actual distance along the surface of the earth will be different (since the earth is not in fact flat), and if you need that you can use the Haversine formula, code for which can be found on the File Exchange.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by