フィルターのクリア

How to speed up the plot?

6 ビュー (過去 30 日間)
BabyMilo
BabyMilo 2012 年 3 月 1 日
How to speed up the plot?
Here is the code if you are too lazy to download it :P :
function bouncer
% BOUNCER Simple illustration of gravity.
[z0,h] = initialize_bouncer;
g = 9.8; % Gravity
c = 0.75; % Elasticity
delta = 0.005; % Time step
v0 = 21; % Initial velocity
while v0 >= 1
v = v0;
z = z0;
while all(z >= 0)
set(h,'zdata',z)
drawnow
v = v - delta*g;
z = z + delta*v;
end
v0 = c*v0;
end
finalize_bouncer
end
%-----------------------------------------------
function [z,h] = initialize_bouncer
% INITIALIZE_BOUNCER
% The z-coordinates and the handle for a surf plot of a sphere.
clf
shg
set(gcf,'color','white','numbertitle','off','name',' Bounce')
axes('position',[0 0 1 1])
[x,y,z] = sphere(20);
z = z + 1;
h = surf(x,y,z);
colormap copper
shading interp
axis([-12.5 12.5 -12.5 12.5 0 25.0])
axis square off
view(90,0)
uicontrol('string','TOSS','style','pushbutton', ...
'units','normal','position',[.10 .05 .12 .05], ...
'background','white','fontweight','normal', ...
'enable','off','callback','bouncer')
drawnow
end
%-----------------------------------------------
function finalize_bouncer
set(findobj('string','TOSS'),'fontweight','bold','enable','on')
end

回答 (1 件)

Daniel Shub
Daniel Shub 2012 年 3 月 1 日
IT smells like homework to me ... I hope I am wrong. Can you see how this might help.
cnt = cnt+1;
if ~rem(cnt, 4)
set(h,'zdata',z)
drawnow
end
  3 件のコメント
BabyMilo
BabyMilo 2012 年 3 月 1 日
what does it do*
i mean
Daniel Shub
Daniel Shub 2012 年 3 月 1 日
The slow part of the code is the plotting (specifically the drawnow which causes the screen to refresh). You can see how fast it runs if you comment out the set and drawnow commands. The code I gave causes the screen to only be updated every 4 frames. If you change the 4 to a bigger number you can make the code go faster, but the "movie" will be jumpy.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by