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.
[in,on] = inpolygon(lat,lon,polygon1_x,polygon1_y);
inon = in | on;
idx = find(inon(:));
latcoord = lat(idx);
loncoord = lon(idx);
plot(lon, lat, '.')
plot(polygon1_y, polygon1_x, '.')
plot(loncoord, latcoord, 'gp')
idx = 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.