This question is closed.

Asked by DARLINGTON ETAJE
on 13 Aug 2019

Hello Family,

Please I need to create three circles. Challenge One: Circle 1 is small and going round on the circumference of circle 2. Challenge 2: Circle 2 is nearly as big as circle 3. Circle 2 is the inner circle with close diameter with circle 3. Circle 2 is going round inside circle 3. I have the codes for challenge One and challenge Two individually...the problem is to make the two codes work as one.

Challenge One Codes:

r=18;

R=20;

radius=[r R]

velocity=[45 0]

colors=['c','r'] % This is to just make the points different colors

p=zeros(2,1); %here we will store the handles to delete the point

hold on

for i=1:2 %Loop to create multiple circles

th=0:pi/50:2*pi;

xunit=radius(i)*cos(th);

yunit=radius(i)*sin(th);

h=plot(xunit,yunit);

p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));

%creates a point on each graph

end

time=[0:0.001:100]; %time vector in seconds

for t=1:length(time)

for i=1:2 %Loop to create multiple circles

delete(p(i)); %delete the old point

%computes the new angle for each point as velocity*time

xunit=radius(i)*cos(velocity(i)*time(t));

yunit=radius(i)*sin(velocity(i)*time(t));

%creates a point on each graph

p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));

end

pause(0.01); %wait 0.01 seconds so the plot is displayed

end

hold off

Challenge Two Codes

t = linspace(0,5*pi );

x = cos(t );

y = sin(t );

plot(7*x,7*y)

axis equal

hold on

for t0 = t

h = plot(2*sin(t0),2*cos(t0),'or ','markersize',175);

pause(0.09 )

delete(h )

axis equal

end

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## dpb (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/476015-two-codes-becoming-one#comment_734721

## Rik (view profile)

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/476015-two-codes-becoming-one#comment_734731