I have one dataset (X,Y locations) for forming a polygon, and second dataset to examine its presence or absence in the first dataset's polygon. I am planning to do it with the change of number of datapoints in the first datasets polygon. If the number of datapoints in first polygon is changed after plotting second dataset, then I can say that second dataset is present in first dataset. But i coul not write the proper code for it on Matlab. How can I count the number of datapoints in a polygon?
You can use inpolygon
to check whether each of the points in your second dataset is inside of the polygon formed by your first dataset
is_inside = inpolygon(data2(:,1), data2(:,2), data1(:,1), data1(:,2));
This will yield a logical
array with an entry for each data point. You can then determine the number of points that were inside of the polygon by summing this vector.
nPointsInside = sum(is_inside);