How can I get multiple for loops to run at the same time?

1 view (last 30 days)
%Points
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');
pause(.5)
%Circle B
for b=0:pi/80:pi/8;
pause(.5)
B=A+[10*cos((-pi/8)+b), 10*sin((-pi/8)+b)];
circle2=viscircles(B,5,'LineWidth',2,'Color','green');
end
%Circle C
for c=0:pi/40:pi/4;
pause(.5)
C=B+[10*cos(-(pi/4)+c), 10*sin(-(pi/4)+c)];
circle3=viscircles(C,5,'LineWidth',2,'Color','blue');
end

Answers (1)

Image Analyst
Image Analyst on 8 Dec 2018
To get them to run at the same time, you have to run them on separtae CPU cores. To do that you need to use parfor (instead of for), which is in the Parallel Processing Toolbox.

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!