View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Animated GIF

4.6 | 7 ratings Rate this file 42 Downloads (last 30 days) File Size: 210 KB File ID: #21944 Version:
image thumbnail

Animated GIF


Robert Bemis (view profile)


30 Oct 2008 (Updated )

How to generate an animated GIF from MATLAB

| Watch this File

File Information

This example animates the vibration of a membrane, captures a series of screen shots, and saves the animation as a GIF image file. The animated GIF is also embedded in an HTML page via the published M-File.


This file inspired 3 D Data Viz Contest Animation.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
20 Jul 2015 E. Cheynet

06 Dec 2012 Aaron

Aaron (view profile)

Tim: I had the same ghost image problem; I fixed it by adding 'set(gcf, 'Renderer', 'zbuffer') around line 18 (after 'set(gca, 'nextplot' ...). I also changed the background color to white because the default was grey by using 'set(gcf, 'Color', [1 1 1])'. Hope that helps.

Comment only
09 Jul 2012 Tim

Tim (view profile)

I cannot get the code to run using Matlab version (R2011a) but it will run using Matlab version (R2010a). I have the Image Processing Toolbox for the 2011 version but not the 2010 version. Does anyone have the “fix” for newer version of Matlab? All I get is a single image with a “ghost” of what is behind the figure on the screen.

Comment only
02 Apr 2012 Bogdan Dzyubak

If I use the attached GIF in powerpoint, it does play. If I rerun the code it yields a gif with a single frame. Are any additional inputs necessary?

Comment only
29 Mar 2012 JR King

06 Sep 2011 Sherif

Sherif (view profile)

Very good, thanks.

23 Apr 2011 Joachim

14 Dec 2010 WtFudgE

I am trying to do it with imagesc or imshow, however my gif file doesn't have all the colours in my image, I tried it with a 3D version of the shepp logan phantom, which odly has a minimum value of -5.551115123125783e-017 and a max of 1 and it's a double.
Is there perhaps some setting that could fix this? It plots fine... It just doesn't write all the colours entirely, only like one gray & black

Comment only
02 Mar 2010 Ged Ridgway

Ged Ridgway (view profile)

Am I right in thinking that 'DelayTime',0 means that the speed of the animation is only limited by the viewer's hardware? (In other words, in a years to come, those peaks might be dancing too fast to see!)

Oddly, the documentation for imwrite doesn't say what the default is for this; looking at imagesci/private/writegif.m it appears that it's 0.5 seconds, which seems very long for most animations (as opposed to step-throughs of multiple plots). I would have thought that something like 1/24 (a common choice of frame-rate I believe) would be a reasonable choice. Though writegif rounds to the nearest 100th of a second, so this would actually be 0.04s. Anyway, just a thought.

Comment only
04 Feb 2010 Geoffrey

It would be nice if I could just feed an argument into a function, but the code is effective and easy to edit.

09 Jul 2009 Robert Bemis

Robert Bemis (view profile)

Luca, see the help for GETFRAME. The optional arguments are what you need. :)

Comment only
09 Jul 2009 Luca Cerone

That's almost what I was looking for..
I just wonder how can I display also xlabel, ylabel
and title, and the values on the axis.
Any Idea???
Thank you very much by the way :)

02 Nov 2008 Robert Bemis

Robert Bemis (view profile)

Anders, interesting suggestion. Thanks!

Comment only
31 Oct 2008 Anders Brun

Anders Brun (view profile)

Nice example! You can add anti-aliasing too if you download the Myaa tool and replace every

f = getframe;

h = myaa;
f = getframe;


02 Feb 2010 1.1

Copyright (BSD compliance)

01 Sep 2016

Updated license

Contact us