MATLAB: Error. Movie contains uninitialized frames

errorframemovie

I'm trying to make a movie with the following code:
x=[-3:0.1:3];
y=[-3:0.1:3];
t=[0:0.1:5];
for i = 1:length(t);
[x,y]=meshgrid(-3:.1:3,-3:.1:3);
z=exp(-(x-t(1,i)).^2-(y-t(1,i)).^2);
surf(x,y,z);
axis('tight')
clear('M');
M(i)=getframe;
end
movie(M);
movie2avi(M,'problem_3.avi');
But it's giving the following error when I run it:
Error using hgMovie
Movie contains uninitialized frames
Please how can I solve this?
Thanks

Best Answer

Why are you deleting the M variable in the loop with the clear() function??? Get rid of that.
Related Question