drawnow's low speed

88 Ansichten (letzte 30 Tage)
Mehdi
Mehdi am 9 Mär. 2018
Kommentiert: Mehdi am 26 Mai 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.

Akzeptierte Antwort

Kun Xie
Kun Xie am 4 Mai 2018
Try
pause(0.005)
instead of
drawnow
  1 Kommentar
Mehdi
Mehdi am 26 Mai 2018
Very cool. Solved the problem. Thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by