How can I get multiple for loops to run at the same time?
1 view (last 30 days)
Show older comments
%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
0 Comments
Answers (1)
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.
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!