535Graphics and GUI
% Plot several lines, update the screen after each plot command
N=1000;
x=rand(N,1);
y=rand(N,1);
cla; hold('on'); drawnow
tic, for idx=1:N; plot(x(idx),y(idx)); drawnow; end; toc
⇨ Elapsed time is 33.895913 seconds.
% Plot the same lines, but update screen only at the end: 50x faster!
cla; hold('on'); drawnow
tic, for idx=1:N; plot(x(idx),y(idx)); end; drawnow; toc
⇨ Elapsed time is 0.694960 seconds.
In some cases involving highly interactive GUIs and nongraphic objects, it makes sense
to use drawnow('expose') rather than simple drawnow. Adding the 'expose' parameter
ensures that only the graphic objects are refreshed, and that callback events are not pro-
cessed. This makes drawnow faster, and postpones the proces ...