Here the code :
First, you need to create a m-file
function [X Y] = circle(center,radius,n)
THETA = linspace(0, 2 * pi, n);
RHO = ones(1, n) * radius;
[X Y] = pol2cart(THETA, RHO);
X = X + center(1);
Y = Y + center(2);
Save this code with filename 'circle.m'
Then create a new m-file
function circles(R);
axis([0 2*R 0 2*R]); axis off; grid off; hold on;
[xoc yoc] = circle([R R], R, 1000);
plot(xoc, yoc, '-','linewidth',2,'color',0.5.*rand(1,3));
[xcc ycc] = circle([R R], 1, 1000);
plot(xcc, ycc, '-','linewidth',2,'color',0.5.*rand(1,3));
numlapis = ((2*R) - (R+1)) / 2;
for cnt1 = 1 : numlapis
lapis(cnt1) = cnt1 * 6;
[xcoor ycoor] = circle([R R], cnt1*2, lapis(cnt1)+1);
for cnt2 = 1 : lapis(cnt1)
[xc yc] = circle([xcoor(cnt2) ycoor(cnt2)], 1, 1000);
plot(xc, yc, '-','linewidth',2,'color',0.5.*rand(1,3));
end
end
Save this code with filename 'circles.m'
And about how to use it.
After you save the files, you can call it from command window.
Just type 'circles(any diameter)'
Eq : circles(5);
Note that this function works well with odd number.
Just try :)
Best Answer