MATLAB: How to calculate distance between a point in a given radius inside a geographic coordinate grid

circlecoordinatesearthquakegridMATLABmeshgridradius

Hello all,
I tried to search for similar questions, and I have got different solutions, but nothing to combine all my tasks, hence I still can't find the proper approach for my problem. Some of the approaches include:
I need to create a grid which contains earthquake data, namely longitude and latitude points (N & E geographic coordinates). What I need is to divide the area into a 0.5 km interval 2-D grid in the horizontal coordinates.
For each grid point, I would need to plot a circle with radius 6 km, and count how many events fall within the circle as well as calculate the distance between the center point of the circle and each event point (earthquake event).
Attached is the file containing the earthquake data needed for the analysis.
Cheers,
H.

Best Answer

Here is how i see solution for this question
clc,clear
long = [57;52.1;50;52;43.5;50;53.5;52;43.2];
lat = [16;15.7;13.5;14.5;11.8;13.5;14.5;14;11.7];
step = 1;
x = min(lat):step:max(lat);
y = min(long):step:max(long);
[X,Y] = meshgrid(x,y); % create grid
R = 1; % circle radius
plot(lat,long,'.r') % plot data
hold on
for i = 1:length(x)
viscircles([x(i),y(1)], R) % plot circle
ix = (lat-x(i)).^2 + (long-y(1)).^2 < R^2;
plot(lat(ix),long(ix),'ob') % plot data inside circle (if exists)
end
plot(X,Y,'k',X',Y','k') % plot grid
hold off
view(2)