How to find distance between points in every grid?
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 27 de En. de 2020
Why are you growing points() by one more row, then finding the distances between all of the rows so far and assigning it to DIST, and then growing points() by another row, finding the distances between all of the rows of the now larger matrix, and writing overtop of the previously calculated DIST, and so on?
And since you keep growing points(), is it correct that you want to compare the points from one i, j combination to the points with different i, j combination? Or do you only want to calculate within the block ?
Walter Roberson
el 28 de En. de 2020
nlat = length(lat);
nlon = length(lon);
DIST = cell(nlat, nlon);
for i = 1:nlat
for j = 1:nlon
ind = find(abs(lat1-lat(i))<dLA/2 & (abs(lon1-lon(j))<dLO/2));
points = [ reshape(lat1(ind), [], 1), reshape(lon1(ind), [], 1)];
DIST{i,j} = pdist(points, 'euclidean');
end
end
Sevil Cansu Yildirim
el 28 de En. de 2020
Editada: Sevil Cansu Yildirim
el 28 de En. de 2020
Walter Roberson
el 28 de En. de 2020
Yes.
Respuestas (0)
Categorías
Más información sobre Plot Settings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!