MATLAB Answers

0

How do I step through a sequence of images or animate a plot without flickering?

I would like to step through a sequence of images or animate a plot without flickering.

1 Answer

Answer by MathWorks Support Team on 4 Jan 2017
 Accepted Answer

You can use the 'EraseMode' property for image objects to eliminate flickering. This property controls the technique MATLAB uses to draw and erase image objects.
For instance:
 
load mri
h = imshow(D(:,:,:,1)); set(h,'erasemode','xor');
for i = 2:27
set(h,'cdata',D(:,:,:,i))
pause
end
For more information, refer to the following URL:
For MATLAB versions MATLAB 5.3 through MATLAB 6.5.1 (R13SP1), you can use the DoubleBuffer property to "on". This property controls whether the erasing and redrawing of a rendering occurs on-screen (the default setting) or off-screen (the optional setting). This is useful because it can prevent the "flashing" you might see during animations. Its disadvantage is that the graphics display may take more time (but it shouldn't take more memory since BackingStore information is used). You can change the 'DoubleBuffer' property through SET:
 
get(gcf,'DoubleBuffer') % To query the property
set(gcf,'DoubleBuffer','on') % To turn it on
set(gcf,'DoubleBuffer','off') % To turn it off (the default)
For example:
figure
h=patch([0 1 0 1],[0 1 1 0],'r');
hold on
h1=plot(linspace(0,1,100),linspace(0,1,100),'b');
tic
for i=1:100
set(h1,'Ydata',rand(1,100));
drawnow
end
Elapsed_Time=toc
% Compare the above to the same example, but with 'DoubleBuffer' set to 'On':
figure
set(gcf,'DoubleBuffer','on');
h=patch([0 1 0 1],[0 1 1 0],'r');
hold on
h1=plot(linspace(0,1,100),linspace(0,1,100),'b');
tic
for i=1:100
set(h1,'Ydata',rand(1,100));
drawnow
end
Elapsed_Time=toc
For more information on DoubleBuffer, see the following URL:
https://www.mathworks.com/help/releases/R2014a/matlab/ref/figure_props.html<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/figure_props.html#DoubleBuffer #DoubleBuffer>

  0 Comments

Sign in to comment.