Dear all,
I used this code below in order to select the points that are placed in/on the polygon which is correct and gave me the right answer.
% lat and lon are the coordinates of my 96 points that I want to select between them
% and polygon1_x and polygon1_y are coordinates of the shape file
[in,on] = inpolygon(lat,lon,polygon1_x,polygon1_y); % Logical Matrix
inon = in | on; % Combine ‘in’ And ‘on’
idx = find(inon(:)); % Linear Indices Of ‘inon’ Points
latcoord = lat(idx); % X-Coordinates Of ‘inon’ Points
loncoord = lon(idx); % Y-Coordinates Of ‘inon’ Points
clffigure(1)plot(lon, lat, '.') % Plot All Points
hold onplot(polygon1_y, polygon1_x, '.') % Plot Polygon
plot(loncoord, latcoord, 'gp') % Overplot ‘inon’ Points
hold offidx = idx.';
But I want to edit this code in order to consider each point as the center of 0.5 x 0.5 grid-box and then start checking. So if any part of this box placed in/on polygon I want to select (index) the former point (center).
I attached my data. I tried to edit this by myself but unfortunately it not accomplished well. So any suggestion is highly appreciated.
Thank you all.
Best Answer