drawnow's low speed

91 visualizzazioni (ultimi 30 giorni)
Mehdi
Mehdi il 9 Mar 2018
Commentato: Mehdi il 26 Mag 2018
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.

Risposta accettata

Kun Xie
Kun Xie il 4 Mag 2018
Try
pause(0.005)
instead of
drawnow
  1 Commento
Mehdi
Mehdi il 26 Mag 2018
Very cool. Solved the problem. Thanks.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by