MATLAB: How to select colors for different results inside a scatter plot

scatter plot

So I've been having trouble making the results inside the circe green and the ones outside the circle blue. The results under 1 and inside the radius of the circle should color diferent of the ones bigger than 1.
this is where I am so far:
n=1000;
u=rand(1,n);
v=rand(1,n);
x=2*u-1;
y=2*v-1;
d2=x.^2+y.^2;
d=d2.^0.5;
nc=0;
t=0;
u=0;
r=1;
th=0:pi/100:2*pi
X=r*cos(pi)+t;
Y=r*sin(pi)+u;
for i=1:n
if d(i)<=1
nc=nc+1;
end
end
newpi=4*nc/n
plot(a,b,'red');
hold on
scatter(x,y,'.')
Any help on how to color code different results on a scatter plot?
help would be very appreciated!

Best Answer

mask = d <= 1;
nc = nnz(mask); %you do not need a loop to count
newpi = 4*nc/n;
colortab = [1 0 0; 0 1 0]; %out of circle = red, in circle = green
point_color = colortab(mask+1,:);
scatter(x,y,[],point_color,'.');
And a trick, sort of:
newpi = 4 * mean(mask); %no need to construct nc