How do I create a for loop that can use multiple changing variables?
Show older comments
I am trying to create a for loop in which multiple circles move at the same time; however, each circle has a specific angle that it needs to move. How do I create a for loop to match this movement? I have already tried nested for loops and that did not provided that wanted response. Thank you.
P1=[-15,0];
P2=[-5,0];
plot([P1(1) P2(1)],[P1(2) P2(2)],'LineWidth',5,'Color','black');
A=[0,0];
circle=viscircles(A,5,'LineWidth',2,'Color','black');
axis equal
axis off
for b=0:pi/80:pi/8,c=0:pi/40:pi/4,d=0:3*pi/80:3*pi/8,e=0:pi/20:pi/2
pause(.5)
B=A+[10*cos((-pi/8)+b), 10*sin((-pi/8)+b)];
circle2=viscircles(B,5,'LineWidth',2,'Color','green');
C=B+[10*cos(-(pi/4)+c), 10*sin(-(pi/4)+c)];
circle3=viscircles(C,5,'LineWidth',2,'Color','blue');
D=C+[10*cos(-(3*pi/8)+d), 10*sin(-(3*pi/8)+d)];
circle4=viscircles(D,5,'LineWidth',2,'Color','red');
E=D+[10*cos(-(pi/2)+e), 10*sin(-(pi/2)+e)];
circle5=viscircles(E,5,'LineWidth',2,'Color','yellow');
end
axis equal
axis off
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!