If your results have some form of time dependence, you would probably like to see them in motion. Movie file formats such as .avi, .mpg, etc. can be bulky, low-quality, and unreliable for presentations. Graphics Interchange Files (.gif) are a comparatively lightweight, cross-platform alternative. A .gif file is basically just a sequence of images stitched together, and Matlab can perform this stitching for you.
(Disclaimer: Matlab can also generate movies in .avi/.mpg format, but I tend to avoid that for the reasons mentioned above. Perhaps someone can comment on the “dynamic” capabilities of Matplotlib and R — these might be nice alternatives, but I’ve never used them).
For a simple example, consider a wave function sin(wt + kx). You can make a time-varying .gif of this function using the following code:
x = 0:0.01:2*pi; omega = 0.5; k = 1; for t=1:50 plot(x, sin(omega*t + k*x), 'linewidth', 2, 'color', 'red'); ylim([-1 1]); xlim([0 2*pi]); grid on; % gif utilities set(gcf,'color','w'); % set figure background to white drawnow; frame = getframe(1); im = frame2im(frame); [imind,cm] = rgb2ind(im,256); outfile = 'sinewave.gif'; % On the first loop, create the file. In subsequent loops, append. if t==1 imwrite(imind,cm,outfile,'gif','DelayTime',0,'loopcount',inf); else imwrite(imind,cm,outfile,'gif','DelayTime',0,'writemode','append'); end end
This will produce the following (if the image appears static, you may need to click it to open in a new tab):
From this example, you can see how a movie of any figure can be created fairly easily. Just stick the plotting commands inside a loop, and at the end of each iteration, append to the .gif file.
If you’d like to see a more compelling example, I’ve been using this to generate .gifs of time-varying sensitivity analysis for a watershed. In the figure below, you can see how the spatially distributed cell sensitivity (top-left) changes with time. The top-right panel shows precipitation, and the bottom panel shows the overall time period with a red line to denote the current time.
(Again, you may need to click the image to see the animation). After large rainfall events, sensitivity is concentrated at the watershed outlet (bottom). Over time, it propagates up toward the headwaters. This type of thing is very difficult to convey with static figures, but it’s much more intuitive with a .gif. I hope you find this useful, and thanks for reading.