I'd like to create a 360 degree rotating surface plot using Matlab2013 (Linux 64bit). I can create an animated gif using code snippet beneath but Matlab keeps resizing the surface at some frames throughout the animation (example see [1], frame 56-59). Any idea how I can prevent Matlab from resizing the plot surface?
Thanks in advance for your advice.
function createVideo( FigureHandler, filename )
grid on
set(gca,'ZTickLabel',[]);
set(gca,'YTickLabel',[]);
set(gca,'XTickLabel',[]);
for n = 1:360
view(n,66)
zoom off
drawnow
frame = getframe(FigureHandler);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if n == 1;
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0);
end
end
end
[1] http://postimg.org/image/prib1psq5/
The problem is caused by the axis limits changing with the view, this could be prevented by manually setting the axis limits or by setting the axis properties 'XLimMode'
,'YLimMode'
and 'ZLimMode'
, to 'manual'
.
However other properties (e.g. DataAspectRatio, PlotBoxAspectRatio, etc...) will cause the figure to zoom in and out while rotating
Matlab however provides the vis3d
axis mode to set all of this for you!
All you need to add is:
axis('vis3d')
which should be place after setting ticks etc... but outside the for loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With