5.0

5.0 | 5 ratings Rate this file 157 Downloads (last 30 days) File Size: 209.92 KB File ID: #21944
image thumbnail

Animated GIF

by Robert Bemis

 

30 Oct 2008 (Updated 02 Feb 2010)

How to generate an animated GIF from MATLAB

| Watch this File

File Information
Description

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.

Acknowledgements
This submission has inspired the following:
3-D DataViz Contest Animation
Required Products Image Processing Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
31 Oct 2008 Anders Brun

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

    f = getframe;

with
    h = myaa;
    f = getframe;
    close(h);

Thanks,
Anders

02 Nov 2008 Robert Bemis

Anders, interesting suggestion. Thanks!

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 :)

09 Jul 2009 Robert Bemis

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

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.

02 Mar 2010 Ged Ridgway

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.

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

23 Apr 2011 Joachim  
06 Sep 2011 Sherif

Very good, thanks.

Please login to add a comment or rating.
Updates
02 Feb 2010

Copyright (BSD compliance)

Tag Activity for this File
Tag Applied By Date/Time
image processing Robert Bemis 30 Oct 2008 14:42:42
data export Robert Bemis 30 Oct 2008 14:42:42
simulation Robert Bemis 30 Oct 2008 14:42:42
animation Robert Bemis 30 Oct 2008 14:46:53
gif Robert Bemis 30 Oct 2008 14:46:57
image Robert Bemis 30 Oct 2008 14:47:01
tutorial Robert Bemis 04 Nov 2008 09:00:10
animation Cristina McIntire 07 Nov 2008 12:52:27
data export Cristina McIntire 10 Nov 2008 10:48:51
image processing Cristina McIntire 10 Nov 2008 10:48:55
data import Cristina McIntire 10 Nov 2008 11:02:24
animation Yang Kuiyuan 15 May 2009 23:13:00
image processing A 07 Jun 2009 08:50:03
gif A 07 Jun 2009 08:50:10
animation A 07 Jun 2009 08:50:13
simulation francesco romano 28 Jun 2010 10:30:35
tutorial francesco romano 28 Jun 2010 10:30:38
animation kuoping 29 Jun 2010 07:09:47
animation Jose Ercolino 27 Aug 2010 11:36:54
gif Tamás Király 19 Jun 2011 15:08:17
animation Max 15 Oct 2011 05:22:36

Contact us at files@mathworks.com