Matlab: Smooth Rotating Animation for Line Plots

I recently became stuck trying to create an animation which consists of a smooth rotation of a viewpoint around the Lorenz attractor. Methods I use for changing viewpoints with respect to surface objects were creating jerky, lagging animations when applied to my line plot.

This will work for any 3D line plot:

plot3(x,y,z);
axis vis3d
fps = 60; sec = 10;
vidObj = VideoWriter('plotrotation.avi');
vidObj.Quality = 100;
vidObj.FrameRate = fps;
open(vidObj);
for i=1:fps*sec
camorbit(0.9,-0.1);
writeVideo(vidObj,getframe(gcf));
end
close(vidObj);

This results in the following smooth animation:

2 thoughts on “Matlab: Smooth Rotating Animation for Line Plots”

1. Thank You!!! says:

You are a God amongst men!!! I have been trying for over a week to get a 3D plot to rotate smoothly. It kept jumping around as it rotated, zooming in and out, giving weird perspectives, etc. etc. I’ve scoured every Stackoverflow and mathworks post on the issue, consulted every matlab coder I know, NO ONE could figure it out.

The solution? “axis vis3d”

I have no idea why those 9 characters solved all of the world’s problems but they did. Thanks.

2. پروژه متلب says:

Was very interesting, thanks for share