MATLAB: Drawnow’s low speed

drawnowMATLAB

Hello, I have written a code which animates the motion of a ball. Here is the code:
n = 100;
axes('XLim', [-10 10], 'YLim', [-10 10], 'ZLim', [-10 n]);
grid on
daspect([1, 1, 1])
axf = gca;
axf.Clipping = 'off';
material shiny
view(135, 10)
set(gcf, 'Renderer', 'opengl')
camlight right
lighting gouraud
xlabel('x')
ylabel('y')
zlabel('z')
[xsph, ysph, zsph] = sphere(500);
h = surface(10*xsph, 10*ysph, 10*zsph, 'FaceColor', 'r', 'EdgeColor', 'none');
w = hgtransform;
set(h, 'parent', w)
zp = 1:n;
yp = zeros(numel(zp));
xp = zeros(numel(zp));
ip = 1;
while ip < n
transr = makehgtform('translate', [xp(ip) yp(ip) zp(ip)]);
set(w, 'Matrix', transr);
ip = ip + 1;
drawnow
end
However the drawnow function slows down the speed of animation drastically. I read other related threads but those suggestions seem not to be applicable to this code, as I'm using surface and not updating any image or video. I wonder if anyone could help me speed up the code a little bit. Thanks a lot.

Best Answer

Try
pause(0.005)
instead of
drawnow