Running n instances of the same function simultaneously

1 visualización (últimos 30 días)
Eythan Haimov
Eythan Haimov el 3 de Sept. de 2022
Respondida: Matt J el 3 de Sept. de 2022
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!

Respuestas (1)

Matt J
Matt J el 3 de Sept. de 2022
You can use parfeval, assuming you have the Parallel Computing Toolbox.

Categorías

Más información sobre Platform and License en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by