MATLAB: Refitting points to nearest polygon

advancedarrayarrayfuncoordinatesfunctionsinpolygonMATLABplotpolygonsshapestest

Hey everyone!
Let's say I have a couple of 2D polygons, and a set of coordinates.
I'm trying to count the number of points that fall in each polygon, and I'm already using inpolygon to do this.
However, I notice there are a few points that are not inside the polygons, but are near it. This is likely due to the inaccuracies that rise with observations.
I need to have these points be counted as part of their nearest polygon, but I don't know how to!
Cheers.

Best Answer

Are you representing your polygons as a polyshape array? polyshape was introduced in release R2017b. If you are, you could try using the buffer-based approach described in Loren's blog combined with the isinterior function.