Videos are cool. But if you need an animation to put in documentation or a PowerPoint then GIF is the way to go.
So building on the previous post of getting a video of your simulation from matlab, this post explains three simple steps to get a GIF animation from mat lab.
The steps are simple.
1. Define the data structure to hold the image data.
2. Plot and get the frame
3. Store the frame image in the data structure
4. Create the GIF animation.
As always lets begin with a data to plot.
Won’t explain much about the data structures and command as Matlab documentation does a good job at that.
I will explain the how to of doing it without much effort. Leave a comment if you are stuck, will try to resolve it.
1. Define the data structure or for shortcut let Matlab provide it.
plot(x(:,k)) figure, f = getframe; [im,map] = rgb2ind(f.cdata,256,'nodither');
2. Store and get the frame image in the data Structure.
im is the data structure.
for k=1:10, plot(x(:,k); f=getframe; im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither'); end
rgb2ind gets the pixel data to the im data structure.
3. Write out the image file.
check Matlab help for other options.
Well that’s it. 3 steps for a gif animation from matlab
While I am with Matlab, I like this little bit of interesting history on the birth of Matlab. Shows how little bets bloom into something so big and useful.
Cleve Moler, the chairman of the computer-science department at the University of New Mexico, started developing MATLAB in the late 1970s. He designed it to give his students access to LINPACK and EISPACK without them having to learn Fortran. It soon spread to other universities and found a strong audience within the applied mathematics community. Jack Little, an engineer, was exposed to it during a visit Moler made to Stanford University in 1983. Recognizing its commercial potential, he joined with Moler and Steve Bangert. They rewrote MATLAB in C and founded MathWorks in 1984 to continue its development. These rewritten libraries were known as JACKPAC. In 2000, MATLAB was rewritten to use a newer set of libraries for matrix manipulation, LAPACK.