GIF speed not as expected! Help!
175 views (last 30 days)
Show older comments
Valerio Biscione
on 15 Mar 2015
Commented: Diptangshu Paul
on 14 Sep 2022
Hello. I am trying to generate a GIF of a growing bar. However, the speed of the generating gif is really slow, and I don't understand how to make it faster. The 'DelayTime' is set to 0, and when the animation is generated in MATLAB is looks really fine. However, when I open the bar.gif, the animation is not fluid at all. This is the code
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.5, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0,'WriteMode','append');
end
1 Comment
John D'Errico
on 14 Nov 2017
Edited: John D'Errico
on 14 Nov 2017
@DA Huang: Please don't answer a question with your own question. Use comments to make a comment.
Moved an answer by Da Huang into a comment:
"Have you solve this problem?"
Accepted Answer
Utpal Kumar
on 7 Jul 2017
Edited and the delay time has been set to 0.1 seconds:
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.1, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0.1,'WriteMode','append');
end
2 Comments
More Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!