How can I get multiple for loops to run at the same time?
1 次查看(过去 30 天)
显示 更早的评论
%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 个评论
回答(1 个)
Image Analyst
2018-12-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!