I'm simulating a wave, and animating it by plotting each time step in a loop and using getframe() to store each frame in a struct. I'm using a movie instead of using pause to animate because I'd later like to save the movie.
When I comment out the getframe call, the entire script takes less than half a second to run, but with it, it takes more than 30 seconds.
u is the 2D array used to store the wave height, where each column is a position and each row is a timestep.
How do I make getframe take less time, or, failing that, is there another way I can animate the wave?
figure('visible','off');
hold on
ylim([min(u,[],'all') - 0.1 * range(u,'all'), max(u,[],'all') + 0.1*range(u,'all')]);
F(length(t)) = struct('cdata',[],'colormap',[]);
p = plot(x, u(1, :));
F(1) = getframe(gcf);
for i = 2:length(t)
set(p, 'YData', u(i, :));
F(i) = getframe(gcf);
end
figure('visible', 'on');
movie(gcf, F, 1, fps);