필터 지우기
필터 지우기

Code to draw multiple circles that do not overlap

조회 수: 3 (최근 30일)
H Y
H Y 2018년 1월 12일
편집: Rena Berman 2018년 1월 12일
In Matlab, I try to draw circles randomly as shown in the following figure.
The current situation is drawn like this and I am in trouble because I have no idea how to make it a circle.
%the code of the current situation
t = linspace(0,2*pi,100);
figure
cx = 200 + (rand(20, 1) .* 1000); %center of the circle
cy = 300 + (rand(20, 1) .* 1000); %center
r = 2; %radius
plot(r*sin(t)+cx,r*cos(t)+cy)
y = r*cos(t)+cy
x = r*sin(t)+cx
for i =0:20
fill(x,y,'k')
%fill(r*sin(t)+cx,r*cos(t)+cy, 'k')
r = r+1;
end
i=i+1;
axis([0,1200,0,1200])
axis square

채택된 답변

michio
michio 2018년 1월 12일
편집: michio 2018년 1월 12일
When the inputs are matrices, the functions draw columns of Y versus columns of X. So could you try changing
fill(x,y,'k')
to
fill(x',y','k')
I just transposed the matrices, x and y. The radius might need to be a bigger number though.
P.S. If you perfer, posting questions in Japanese is also always welcome :)
  댓글 수: 1
michio
michio 2018년 1월 12일
I forgot to mention but you do not need the for loop.
for i =0:20
fill(x,y,'k')
end
Simply calling
fill(x',y','k');
would work.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

H Y
H Y 2018년 1월 12일
Thank you. It has worked. I would appreciate if you could give me advice regarding the another question which I have posted. There is no answer from anyone, and what should I do to improve the situation of it?

제품

Community Treasure Hunt

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

Start Hunting!