Using VideoWriter to make a Movie without Displaying the Figure each time

4 views (last 30 days)
I have a variable called movie which is a multidimensional array of a solution to a partial differential equation at every kth time step. I now want to use VideoWriter to make a movie out of this variable. However, it seems to take forever in run-time because Matlab is actually displaying each frame on the screen. Is there anyway to speed this up? My code for this section is attached below:
%%
clf;
vid = VideoWriter('movie_2D.avi');
vid.FrameRate = 20;
open(vid);
frames = 1000;
for i=1:frames
figure(1);
surf(X,Z,movie(:,:,1+(t_max/frames)*i));
colormap parula; shading interp; grid off; colorbar; caxis([-1,1]);
xlim([-x_Max, x_Max])
ylim([0, 1])
% title('N=%d, M=%d, \Delta t=$d, \lambda_0=%d, \lambda_H=%d',N,M,dt,lambda0,lambdaH)
title('N=64, M=32, \Delta t=.0001, \lambda_0=100, \lambda_H=10')
xlabel('x')
ylabel('y')
zlabel('u')
view(0,90);
fig = gcf;
frame = getframe(fig);
writeVideo(vid,frame);
end
close(vid)

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!