Getting Started |
Creating Movies
If you increase the number of points in the Brownian motion example to something like n = 300
and s = .02
, the motion is no longer very fluid; it takes too much time to draw each time step. It becomes more effective to save a predetermined number of frames as bitmaps and to play them back as a movie.
First, decide on the number of frames, say
Next, set up the first plot as before, except using the default EraseMode
(normal
).
x = rand(n,1)-0.5; y = rand(n,1)-0.5; h = plot(x,y,'.'); set(h,'MarkerSize',18); axis([-1 1 -1 1]) axis square grid off
Generate the movie and use getframe
to capture each frame.
for k = 1:nframes x = x + s*randn(n,1); y = y + s*randn(n,1); set(h,'XData',x,'YData',y) M(k) = getframe; end
Finally, play the movie 30 times.
Animations | Programming with MATLAB |