MATLAB: When I play the movie, why is it displayed at an offset from the created axes

anataxescreateddisplayedfromiisitMATLABmoviemyoffsetplaythewhenwhy

When I play my movie in MATLAB, why is it displayed at an offset from the created axes?
For example,
Z = peaks(50);
hfig = figure;
hsurf = mesh(Z);
t=linspace(0,2*pi,16);
set(gca,'zlim',[-10 10]);
for i = 1:15,
Zi = Z.*cos(t(i));
set(hsurf,'zdata',Zi,'cdata',Zi);
M(i) = getframe(hfig);
end;
movie(M);
Why does playing this movie seem to create a new axes and display the movie at an offset from the created axes?

Best Answer

This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
When playing a movie, the default location of the output is in the current axes, and not the current figure. To force it to play in a specified figure, the handle to the figure needs to be passed to the MOVIE function. This will prevent MOVIE from creating a set of axes and playing the frames inside of the axes. For example,
Z = peaks(50);
hfig = figure;
hsurf = mesh(Z);
t=linspace(0,2*pi,16);
set(gca,'zlim',[-10 10]);
for i = 1:15,
Zi = Z.*cos(t(i));
set(hsurf,'zdata',Zi,'cdata',Zi);
M(i) = getframe(hfig);
end;
figure
movie(gcf,M);
This method of calling MOVIE is described in the documentation that can be found at the following URL: