http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944
MATLAB Central Newsreader  How to stop graphics refresh
Feed for thread: How to stop graphics refresh
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 02 Jul 2008 19:34:01 +0000
How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#440852
Aleks
Does anyone know if there is a way to stop refreshing <br>
graphics in matlab? I have a quite complex graphics <br>
program, and it looks like the figure sometimes updates <br>
between calls to drawnow. It makes the image flicker.<br>
<br>
What I want is something like:<br>
<br>
while(running)<br>
do something to figure;<br>
do something else to figure;<br>
do even more to figure;<br>
drawnow;<br>
end<br>
<br>
I need to make sure that the figure is not updated unless <br>
drawnow is called.<br>
<br>
Thanks for your help!

Wed, 02 Jul 2008 20:16:06 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#440865
roberson@ibd.nrccnrc.gc.ca (Walter Roberson)
In article <g4gl79$e9t$1@fred.mathworks.com>,<br>
Aleks <aleksve@hotmail.com> wrote:<br>
>Does anyone know if there is a way to stop refreshing <br>
>graphics in matlab? I have a quite complex graphics <br>
>program, and it looks like the figure sometimes updates <br>
>between calls to drawnow. It makes the image flicker.<br>
<br>
Does the figure need to be visible during the update? <br>
I guess if flickering is a problem then Yes, but if it doesn't<br>
happen to need to be visible during the update, set the figure<br>
visibility off, do the update, and then set the figure visibility<br>
on.<br>
<br>
If the figure does need to be visible, then you could do a doublefigure<br>
process: when you want to do the update, create an invisible figure,<br>
do all the graphics writing to it, and when it is done, make the<br>
new figure visible and the old figure invisible.<br>
<br>
 <br>
"To burn always with this hard, gemlike flame, to maintain this<br>
ecstasy, is success in life."  Walter Pater

Fri, 11 Jul 2008 11:31:02 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#442471
Aleks
If only it was that good... The figure always has to be <br>
visible as it is part of an animation. I am becoming more <br>
and more convinced that the error lies somewhere else. I <br>
tested it with following oneliner:<br>
<br>
i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true), <br>
for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); end; end<br>
<br>
If the figure updated itself without explicit call to <br>
drawnow, the line would produce a running sinus wave. <br>
However, the figure updates itself only once, when the <br>
first sinus is drawn. On the other hand, <br>
<br>
i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true), <br>
for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); drawnow; <br>
end; end<br>
<br>
(added "drawnow" just before "end; end") successfully <br>
produces a running sinus wave.<br>
<br>
Well, thanks for your time anyway :=)<br>
<br>
best regards, Aleksander<br>
<br>
<br>
<br>
roberson@ibd.nrccnrc.gc.ca (Walter Roberson) wrote in <br>
message <g4gnm6$cnk$1@canopus.cc.umanitoba.ca>...<br>
> In article <g4gl79$e9t$1@fred.mathworks.com>,<br>
> Aleks <aleksve@hotmail.com> wrote:<br>
> >Does anyone know if there is a way to stop refreshing <br>
> >graphics in matlab? I have a quite complex graphics <br>
> >program, and it looks like the figure sometimes updates <br>
> >between calls to drawnow. It makes the image flicker.<br>
> <br>
> Does the figure need to be visible during the update? <br>
> I guess if flickering is a problem then Yes, but if it <br>
doesn't<br>
> happen to need to be visible during the update, set the <br>
figure<br>
> visibility off, do the update, and then set the figure <br>
visibility<br>
> on.<br>
> <br>
> If the figure does need to be visible, then you could do <br>
a doublefigure<br>
> process: when you want to do the update, create an <br>
invisible figure,<br>
> do all the graphics writing to it, and when it is done, <br>
make the<br>
> new figure visible and the old figure invisible.<br>
> <br>
>  <br>
> "To burn always with this hard, gemlike flame, to <br>
maintain this<br>
> ecstasy, is success in life."  Walter <br>
Pater

Fri, 11 Jul 2008 11:43:02 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#442472
Jos
"Aleks " <aleksve@hotmail.com> wrote in message<br>
<g57g9m$ap5$1@fred.mathworks.com>...<br>
> If only it was that good... The figure always has to be <br>
> visible as it is part of an animation. I am becoming more <br>
> and more convinced that the error lies somewhere else. I <br>
> tested it with following oneliner:<br>
> <br>
> i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true), <br>
> for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); end; end<br>
> <br>
> If the figure updated itself without explicit call to <br>
> drawnow, the line would produce a running sinus wave. <br>
> However, the figure updates itself only once, when the <br>
> first sinus is drawn. On the other hand, <br>
> <br>
> i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true), <br>
> for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); drawnow; <br>
> end; end<br>
> <br>
> (added "drawnow" just before "end; end") successfully <br>
> produces a running sinus wave.<br>
> <br>
> Well, thanks for your time anyway :=)<br>
> <br>
> best regards, Aleksander<br>
> <br>
> <br>
> <br>
> roberson@ibd.nrccnrc.gc.ca (Walter Roberson) wrote in <br>
> message <g4gnm6$cnk$1@canopus.cc.umanitoba.ca>...<br>
> > In article <g4gl79$e9t$1@fred.mathworks.com>,<br>
> > Aleks <aleksve@hotmail.com> wrote:<br>
> > >Does anyone know if there is a way to stop refreshing <br>
> > >graphics in matlab? I have a quite complex graphics <br>
> > >program, and it looks like the figure sometimes updates <br>
> > >between calls to drawnow. It makes the image flicker.<br>
> > <br>
> > Does the figure need to be visible during the update? <br>
> > I guess if flickering is a problem then Yes, but if it <br>
> doesn't<br>
> > happen to need to be visible during the update, set the <br>
> figure<br>
> > visibility off, do the update, and then set the figure <br>
> visibility<br>
> > on.<br>
> > <br>
> > If the figure does need to be visible, then you could do <br>
> a doublefigure<br>
> > process: when you want to do the update, create an <br>
> invisible figure,<br>
> > do all the graphics writing to it, and when it is done, <br>
> make the<br>
> > new figure visible and the old figure invisible.<br>
> > <br>
> >  <br>
> > "To burn always with this hard, gemlike flame, to <br>
> maintain this<br>
> > ecstasy, is success in life."  Walter <br>
> Pater<br>
> <br>
<br>
Try to set the doublebuffer property to on.<br>
<br>
Jos

Fri, 11 Jul 2008 16:09:43 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#442515
Nasser Abbasi
<br>
"Aleks " <aleksve@hotmail.com> wrote in message <br>
news:g57g9m$ap5$1@fred.mathworks.com...<br>
<br>
> i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true),<br>
> for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); end; end<br>
><br>
> If the figure updated itself without explicit call to<br>
> drawnow, the line would produce a running sinus wave.<br>
> However, the figure updates itself only once, when the<br>
> first sinus is drawn. On the other hand,<br>
><br>
> i = 0:0.01:2*pi; h = plot(sin(i)); drawnow; while(true),<br>
> for j = 0:0.01:2*pi; set(h, 'YData', sin(ij)); drawnow;<br>
> end; end<br>
><br>
> (added "drawnow" just before "end; end") successfully<br>
> produces a running sinus wave.<br>
><br>
<br>
I've always put a drawnow when I want stuff to appear on display. So I am <br>
not sure why you were expecting the plot to show up inside the loop without <br>
having to add a drawnow there?<br>
<br>
Just becuase you put a "drawnow" outside the loop has no effect.<br>
<br>
This is what I normally do.<br>
<br>
loop<br>
plot(...);<br>
.......<br>
plot(..)<br>
.......<br>
drawnow;<br>
pause(...)<br>
end<br>
<br>
<br>
Nasser

Mon, 09 Mar 2009 07:23:02 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#633420
Alon
I encountered this problem myself in several occasions, and didn’t find anywhere an elegant solution.<br>
I event went into java in hope to control the eventqueue.<br>
Finally  giving up on an elegant solution  I approached the problem in "brought force", with the presented solution, which visually gave me exactly what I wanted.<br>
Basically what I'm doing is a crude ZBuffer:<br>
I copy the figures content, display it in front, and after all the graphic operations have finished  delete the overlaying image:<br>
<br>
F=getframe(figH);<br>
D=F.cdata; Handle=uicontrol(figH,'Style','pushbutton','units','normalized','position',[0,0,1,1],'cdata',D);<br>
uistack(Handle,'top');<br>
drawnow;<br>
%...<br>
% All the graphic operatoins<br>
%...<br>
drawnow;<br>
pause(0.1);<br>
delete(Handle);<br>
<br>
Hope that helps,<br>
Alon Walter.

Mon, 09 Mar 2009 08:16:01 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#633425
Yair Altman
"Alon " <zarboov@hotmail.com> wrote in message<br>
[snip]<br>
> I copy the figures content, display it in front, and after all the graphic operations have finished  delete the overlaying image:<br>
> <br>
> F=getframe(figH); D=F.cdata;<br>
> Handle=uicontrol(figH,'Style','pushbutton','units','normalized','position',[0,0,1,1],'cdata',D);<br>
> uistack(Handle,'top');<br>
> drawnow;<br>
> %...<br>
> drawnow;<br>
> pause(0.1);<br>
> delete(Handle);<br>
<br>
This is a great trick, Alon :)<br>
The only drawbacks are that the main figure toolbar disappears during the operation. Also, the image does not resize when the figure resizes, so perhaps it's best to make the figure modal for the duration.<br>
I would also suggest adding (...,'enable','inactive') so the uicontrol is not "clickable".<br>
<br>
Yair Altman

Mon, 09 Mar 2009 08:38:01 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#633426
Rodney Thomson
"Aleks " <aleksve@hotmail.com> wrote in message <g4gl79$e9t$1@fred.mathworks.com>...<br>
> Does anyone know if there is a way to stop refreshing <br>
> graphics in matlab? I have a quite complex graphics <br>
> program, and it looks like the figure sometimes updates <br>
> between calls to drawnow. It makes the image flicker.<br>
> <br>
> What I want is something like:<br>
> <br>
> while(running)<br>
> do something to figure;<br>
> do something else to figure;<br>
> do even more to figure;<br>
> drawnow;<br>
> end<br>
> <br>
> I need to make sure that the figure is not updated unless <br>
> drawnow is called.<br>
> <br>
> Thanks for your help!<br>
<br>
> I need to make sure that the figure is not updated unless <br>
> drawnow is called.<br>
<br>
I normally have the opposite problem where graphics are NOT redrawn when I wish them to. That is where a drawnow can be useful.<br>
<br>
The default behavior for MATLAB is to not redraw unless one of the following occurs (taken from the doc page for 'drawnow')<br>
<br>
 Other Events That Cause Event Queue Processing <br>
<br>
Other events that cause MATLAB to flush the event queue and draw the figure includes:<br>
<br>
* Returning to the MATLAB prompt<br>
* Executing the following functions<br>
o figure<br>
o getframe<br>
o input<br>
o keyboard<br>
o pause<br>
* Functions that wait for user input (i.e., waitforbuttonpress, waitfor, ginput)<br>
* Any code that causes one of the above functions to be executed. For example, suppose h is the handle of an axes. Calling axes(h) causes its parent figure to be made the current figure and brought to the front of all displayed figures, which results in the event queue being flushed.<br>
<br>
So if you don't want flickering, make sure none of your code in your loop does anything mentioned above and have a solitary drawnow at the end of each loop block. If so, then find an alternative method to acheive this (ie how you can do set(handle, 'XData', 0:10, 'YData', 10:1:0) instead of plot(0:10, 10:1:0))<br>
<br>
Cheers<br>
<br>
Rod<br>
<br>
p.s. did noone else chuckle at the running sinus? Maybe its just me... Its been a long day here! Also sorry if I am double / triple posting. I'm getting a lot of server errors from Mathworks.

Mon, 09 Mar 2009 10:02:36 +0000
Re: How to stop graphics refresh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/171944#633439
Rune Allnor
On 9 Mar, 08:23, "Alon " <zarb...@hotmail.com> wrote:<br>
> I encountered this problem myself in several occasions, and didn=92t find=<br>
anywhere an elegant solution.<br>
> I event went into java in hope to control the eventqueue.<br>
> Finally  giving up on an elegant solution  I approached the problem in =<br>
"brought force", with the presented solution, which visually gave me exactl=<br>
y what I wanted.<br>
> Basically what I'm doing is a crude ZBuffer:<br>
<br>
This ought to be formalized into matlab. What about<br>
adding a figure (and/or axis) property 'redrawmode'<br>
that could be set to 'auto' or 'manual'. In 'auto'<br>
the figure behaves as it does today, with the figure<br>
being redrawn on the fly. In 'manual' mode the graphics<br>
is drawn in a buffer but the screen is not updated<br>
until an explicit command (REDRAW ?) is called.<br>
<br>
Something for TMW to consider?<br>
<br>
Rune