How to find distance between points in every grid?

3 views (last 30 days)
Hello, I defined a grid onto a map that I plotted with MAP library. This grid contains some elements and I know the density of each grid (which one contains what amount of elements). But now I need to find which element belongs to which grid and calculate distance between these points belonging to same grid.
Here is my code, and you can find the data and the figure attached. Thank you from now.
clear all;figure;
addpath('D:\Desktop\BOUN\JOB\Slip_Rates\Slip_Data\MAP');
LAT1=39;LAT2=42;LON1=29.0;LON2=41.0;
sf = 1;
m_proj('albers equal-area','lat',[LAT1 LAT2],'long',[LON1 LON2],'rect','on');m_gshhs_h('color',[.5 .5 .5]);hold on;
m_grid('linewi',1,'linest','none','tickdir','in','fontsize',10);
all = load('all_velocities.txt');
lon1=all(:,1);lat1=all(:,2);ve1=all(:,3);vn1=all(:,4);
%[lon1,lat1,ve1,vn1,sve1,svn1] = textread('all_velocities.txt','%f %f %f %f %f %f'); % REFERENCE
%density of the grids
dLO = .5*2; dLA = .3636*2;
lon = [LON1:dLO:LON2]; % grid size longitude
lat = [LAT1:dLA:LAT2]; % grid size latitude
for i = 1:length(lat)
for j = 1:length(lon)
DENSITY(i,j) = length(find(abs(lat1-lat(i))<dLA/2 & (abs(lon1-lon(j))<dLO/2)));
end
end
% distance between vectors in every single defined grids
z = 1;
for i = 1:length(lat)
for j = 1:length(lon)
ind = find(abs(lat1-lat(i))<dLA/2 & (abs(lon1-lon(j))<dLO/2));
for k = 1:length(ind)
points(z,:) = [lat1(ind(k)) lon1(ind(k))];
DIST = pdist(points, 'euclidean');
z = z+1;
end
end
end
m_pcolor(lon-dLO/2,lat-dLA/2,DENSITY);colormap(jet);colorbar;
m_quiver(lon1,lat1,sf.*ve1,sf.*vn1,1,'w','filled','AutoScale','off','linewidth',1.5);
hold off;
  4 Comments
Sevil Cansu Yildirim
Sevil Cansu Yildirim on 28 Jan 2020
Edited: Sevil Cansu Yildirim on 28 Jan 2020
I am sorry to ask but, in this case, is these DIST{} indicates the distances between the points in every 5x13 grid I defined? If so, thank you.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!