# How to plot multiple circles within a circle by using a for-loop for radius/center position?

23 views (last 30 days)
Sandeep Kumar on 27 Sep 2021
Commented: Johan on 30 Sep 2021
Hi,
I want to plot multiple equisized small circles filling within a sector bigger circle.
The center of each of the smaller circle changes as radial distance with respect to the center of bigger cirlce, as can be seen from the attached image. And the smaller circles are to be filled with color map, ranging from 0 to 1.
This entire plotting will then be in a time loop from 1 to 100 sec.
It will be of great help if anyone can share thoughts, and if possible, brief code.
Thanks!
Sandeep
##### 1 CommentShowHide None
Sandeep Kumar on 28 Sep 2021
Hi,
Since, I am sort of rookie in using Matlab, I am not able to process the function properly and use it.
Can you elaborate a bit more by plotting demonstration one, if possible. It will be very helpful.
Thanks!
Best Regards,
Sandeep

Johan on 27 Sep 2021
Hi,
I have been working with somewhat similiar plotting needs. To plot circles I used the polyshape built-in function with the code below. With this function you can directly call plot(CoordCircle(radius,xcenter,ycenter) and update your plot following your needs. You can look up the polyshape function for details on plotting, you can change transparency and color as suits your need.
function RES = CoordCircle(r,x0,y0)
t = 0:0.05:2*pi;
x1 = r*cos(t)+x0;
y1 = r*sin(t)+y0;
RES = simplify(polyshape(x1,y1));
end
To make your time depend representation, I would start by plotting all the circles you want, compute the new radii then update your plotted circle by using the figure handle, clf and drawnow function.
Hope this helps,
Johan
Johan on 30 Sep 2021
1) Yes you can plot two circle at the same x,y but with different r and use the option.
plot(...., 'FaceAlpha', 0)
to make one circle's interior transparent.
If you need to limit the radius or center of a circle compared to another you will need to set condition to your x,y,r parameters before you plot.
2) I'm not sure exactly what you mean, if you want matlab to handle the colors automatically you can remove the 'FaceColor',[1,0,0] option of the plot.
Best,
Johan

### More Answers (1)

Image Analyst on 27 Sep 2021
If you have a list of the centers and radii, and the Image Processing Toolbox, I'd simply use the function meant for displaying circles: viscircles()
Lots of options you can use to change the way the circles look (color, linewidth, etc.), so look into those.
Image Analyst on 29 Sep 2021
To plot an arc, see the FAQ:
You'd have to figure out the starting and stopping angle. That part is not MATLAB - it's just pure 10th grade math/geometry so I'm sure you can do it. Worst case you can plot just a point and a time and check if the point is farther away or closer from the containing circle's center than the containing circle's radius. Plot a dot if it's closer and don't plot a dot if it's farther away. Use sqrt() to get the Euclidean distance using the Pythagorean theorem.

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!