MATLAB: How to fill a rectangle (or circle) in a matrix

circlecoordinatesfillpolygonrectangle

Imagine the following matrix.
1 1 1 1 1 1 1 1 1 1
1 1 10 10 10 10 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 10 10 10 10 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
I know the coordinates of the 10's. they are stored in A and B. How do I use the known coordinates of 10's to fill in the 1's within the square of 10's? thanx for help.
I have simplified my problem here. I have extracted the essence of the problem above. But for those interested I'll explain the following. I want to create a filled circle inside a bigger matrix. Since I have the coordinates of the outer circle, I need a way to fill in the inside. My code:
k=zeros(300,300)+200
for theta=0:.001:7;
radius=10
[X,Y] = pol2cart(theta,radius);
A=[round(X)+radius];
B=[round(Y)+radius];
ring = sub2ind(size(K),A,B);
kleur=90;
K(A,B) = kleur;
end

Best Answer

Here's one way to fill the space between the top row of 10s and the bottom row of 10s:
K= [1 1 1 1 1 1 1 1 1 1
1 1 10 10 10 10 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 1 1 1 10 1 1 1
1 1 10 10 10 10 10 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1];
for cols = 1:size(K,2);
K(find(K(:,cols)==10,1,'first'):find(K(:,cols)==10,1,'last'),cols) = 10;
end