Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Matlab from resizing the surface when creating an animated gif


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/

like image 266
Durin Avatar asked Oct 21 '22 06:10

Durin


1 Answers

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

like image 171
RTL Avatar answered Oct 23 '22 04:10

RTL