drawnow's low speed

79 次查看(过去 30 天)
Mehdi
Mehdi 2018-3-9
评论: Mehdi 2018-5-26
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.

采纳的回答

Kun Xie
Kun Xie 2018-5-4
Try
pause(0.005)
instead of
drawnow

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by