Saturday, February 25, 2012

MATLAB Graph: Animation

This post just shows how a simple animation is constructed.

Two ways to create animated sequence:

  • save a number of different pictures and then play them back as a movie
  • continuously erase & redraw the object on screen
Remember, a movie is not rendered in real time, it is just a playback of previously rendered frames.

Two steps to "save & replay":
  1. use "getframe" to generate each movie frame
  2. use "movie" to run the movie
when one use "getframe" two properties are returned:
  1. cdate: Image data in a uint8 matrix: The matrix has dimensions of height-by-width on indexed-color systems and height-by-width-by-3 on truecolor systems
  2. colormap:  The colormap in an n-by-3 matrix, where n is the number of colors. On truecolor systems, the colormap field is empty. 
Example:
h = uicontrol('style','slider','position',...
    [10 50 20 300],'Min',1,'Max',16,'Value',1)
for k = 1:16
    plot(fft(eye(k+16)))
    axis equal
    set(h,'Value',k)
    M(k) = getframe(gcf);
end

clf
axes('Position',[0 0 1 1])
movie(M,30)

No comments:

Post a Comment