MATLAB: How to create a grid in 2D space with a shape cut out of the grid

gridMATLABmeshgrid

Hello,
I've got a uniformly spaced grid and I have a shape overlapping the bottom right side of the grid. I'd like that shape to act as a boundary and as such, not contain any grid points within the shape. See the example code:
[X,Y]=meshgrid(-1:0.1:1,-1:0.1:1); %Grid of XY coordinates
theta=pi/2:0.01:pi; %Angular arc of circle
R=1.0; %Radius of circle
Xcirc=R*cos(theta)+1; %Cartesian coordinates for X of circle
Ycirc=R*sin(theta)-1; %Cartesian coordinates for Y of circle
hold on
plot(X,Y,'+')
plot(Xcirc,Ycirc)
How do I cut out the grid points which lie within the circle?
Thank you for any help or suggestions.

Best Answer

See if this does what you want:
[in, on] = inpolygon(X, Y, [ Xcirc -1], [-1 Ycirc ]);
plot(X(~in & ~on),Y(~in & ~on),'+')
hold on
plot(Xcirc,Ycirc)
It eliminates the points within the shape. You may want to experiment with the inpolygon call if this is not the exact result you want.