How to set multiple pause() in a for-loop?

I am trying to create an animation using 3 types of plot. After each of them I want to set a pause. My code looks like this:
for i= :
p1=plot1();
pause(delay1);
p2=plot2();
pause(delay2);
p3=plot3();
pause(delay3);
delete(p1);
delete(p2);
delete(p3);
drawnow
handles = guidata(hObject);
end
The problem is that the pauses get sumed and when the code ritch plot 3 is a very big delay. Can you help me whith this situation?

1 Comment

Silviu - what are the values for delay1, delay2 and delay3? The pause should not be "summed" so perhaps an incorrect value has been assigned to one or more of these delay variables.

Sign in to comment.

Answers (1)

Jan
Jan on 24 Jun 2017
Edited: Jan on 24 Jun 2017
The problem must be somewhere else, because the shown code works:
figure;
axes('NextPlot', 'add');
for i = 1:20
p1 = plot(1:10, rand(1, 10));
pause(0.5);
p2 = plot(1:10, rand(1, 10));
pause(0.5);
p3 = plot(1:10, rand(1, 10));
pause(0.5);
delete(p1);
delete(p2);
delete(p3);
drawnow
end
The delays appear exactly where they are wanted.
What is "plot1", "plot2" and "plot3"? What is the purpose of the guidata command?

Asked:

on 24 Jun 2017

Edited:

Jan
on 24 Jun 2017

Community Treasure Hunt

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

Start Hunting!