Running n instances of the same function simultaneously

1 次查看(过去 30 天)
Hi,
I have a GUI written in appdesigner with a function that takes a data matrix and uses it to display a "frame", running this in a while loop results in a video being played. This is the code for it:
function PlayButtonPushed(app, event)
% Start conditions
Frame = app.CurrentFrame.Value;
PauseTime = app.TimeBetweenFrames.Value;
NumOfFrames(1) = app.Arena(1).File.NumberOfFrames;
% Main loop
while Frame <= NumOfFrames
DisplayFrame(app, Frame);
drawnow % Update GUI after displaying frame
pause(PauseTime);
% Stop condition
if strcmp(app.StopValue, 'On')
app.StopValue='Off';
break
end
% Update conditions for the next frame
FrameInterval = app.FrameInterval.Value;
Frame = app.CurrentFrame.Value+FrameInterval;
app.CurrentFrame.Value = Frame;
PauseTime = app.TimeBetweenFrames.Value;
app.TimeBetweenFrames.Value = PauseTime;
end
end
So as you can see, app.Arenas is an array and currently it only display the first arena, I would like to expand on it, being able to view two or four(or n, for a generallity) arenas at the same time. I could just loop the "DisplayFrame" function for n but I may want to take in to account the fact that maybe different arenas have a different "total frames" for them, and also, looping it will be a lot slower.
Is there anyway to have this function run multiple times, simultaneously?
Thanks!

回答(1 个)

Matt J
Matt J 2022-9-3
You can use parfeval, assuming you have the Parallel Computing Toolbox.

类别

Help CenterFile Exchange 中查找有关 Platform and License 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by