Running n instances of the same function simultaneously

1 回表示 (過去 30 日間)
Eythan Haimov
Eythan Haimov 2022 年 9 月 3 日
回答済み: Matt J 2022 年 9 月 3 日
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 Center および File ExchangePlatform and License についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by