MATLAB: How to plot a number of circles with the same radius, but the position of the circles is randomly put

circleMATLABrandom positions

I need to plot a number of circles with the same radius. Number of circles and the radius are input parameters. Also circles are randomly positioned. For example: The program ask user to input the number of the circles, then ask to input the radius of the circle. Here, the radius is the same for all circles. Then by using input parameters program randomly put the circles.

Best Answer

N = 10 ; % number of circles
r = 0.25 ; % radius of circel
%

C = rand(N,2) ;
%
th = linspace(0,2*pi) ;
x = r*cos(th) ;
y = r*sin(th) ;
% Loop for each circle
for i = 1:N
xc = C(i,1)+x ;
yc = C(i,2)+y ;
hold on
plot(xc,yc) ;
end
axis equal