MATLAB: Most effective way to fix axes for 3-D animation

animationplottingvisualization

Hello, I have some data that I would like to animate. The code is below:
The vectors x(:,i), y(:,i), and z(:,i), are the coordinates of various points in space, where i is the ith frame of the animation; the value x(j,i) would be the jth point in the ith frame of the animation. All points are plotted simultaneously.
for i = 1:size(x,1)
plot3(x(:,i), y(:,i), z(:,i), 'go'); axis(axislimits);
set(gca,'Color',[0.1 0.1 0.1],'Xcolor',[1 1 1],'Ycolor',[1 1 1],'Zcolor',[1,1,1]);
axis square; grid on; pause(1/60);
end
Is there a way to set the axis properties, so that MATLAB won't have to redraw it every time it goes through the loop?

Best Answer

In the loop you only need to update the the XData, YData and ZData. Something like
for ii = 1 : size( x, 2 )
set( graphic_handle, 'XData', x(:,ii), 'YData', y(:,ii), 'ZData', z(:,ii) )
pause(1/60)
end
See: Lineseries Properties