Pausing and continuing an animation in App Designer

4 views (last 30 days)
Hey everyone I'm trying to pause an animation I made.
Following is the loop that generates the animation.
Before, the position over time of the falling objects are calculated and saved as a vector.
Objects are generated by the patch command.
With every iteration of the loop the new position is shown in a figure.
tu is the time the objects fall until they hit the ground.
tf is a vector with the time intervals between 0 and tu.
tf consists of as many columns as needed to guarantee 25 frames per seconds.
So far everything works as planed.
%Schleife zur Animation
q = 1;
time = 0;
tic;
while time < tu
time = toc;
%Anzeigewerte
app.GeschwindigkeitEditField.Value = vt(q);
app.aktuelleZeitEditField.Value = tf(q);
app.StreckeEditField.Value = st(q);
app.kinetischeEnergieEditField.Value = Ekin(q);
app.potentielleEnergieEditField.Value = Epot(q);
app.GesamtenergieEditField.Value = Eges(q);
app.rotatorischeEnergieEditField.Value = 0; % visualisation of Information about velocity, energy, time etc.
%Position der Scheibe
Kreis.XData = xAkreis + R;
Kreis.YData = yAkreis + y(q); % positon of first falling object
InnenKreis.XData = xIkreis + R;
InnenKreis.YData = yIkreis + y(q); % positon of second falling object
%Grenzen des Diagramms
xlim([-R 20+R]);
ylim([-H-Boden*3/2 R+2]);
pau = tf(q) - toc;
pause(pau); % forcing matlab to wait until predefined time (tf)
q = q + 1;
if q > length(tf)
q = length(tf);
end
end
I now want to pause my animation at any point and continue it at the same point.
I tried a second infinite while loop inside the first one that is started by using a switch in app designer but if it started it started with different delays and didn't continue after I used the switch again.
Thanks for any help!
  4 Comments
Mario Malic
Mario Malic on 8 Nov 2020
Great! I'll post this as an answer and you can accept it. Thanks in advance.
MSolano
MSolano on 7 Jul 2021
I'm having a very similar issue, but I just can't find the answer, how were you able to solve this?? Just with the if and while loops inside your animation loop?

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!