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 ondaspect([1, 1, 1])axf = gca; axf.Clipping = 'off'; material shinyview(135, 10)set(gcf, 'Renderer', 'opengl')camlight rightlighting gouraudxlabel('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; drawnowend
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