Message Boards Message Boards

0
|
7222 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Print over previous output while evaluating?

Posted 3 years ago

I am running something like

For[count=1,count<=5000, count++,  
       Print["count = ",count];  
      pass  
]  

where "pass" takes a few seconds to run. So the whole thing takes some hours. Printing "count" gives me a warm feeling that it is moving along. But it fills the screen in an unpleasant way. What I would like to happen is that
count =1
appears on the screen, while pass runs for the first time, and then is REPLACED ON THE SCREEN (OVERWRITTEN) by
count=2
while pass runs for the second time, and so on. So I get the warm feeling of watching count increase, without filling the screen.

How can I make this happen?

Thanks

POSTED BY: David Golber
5 Replies

I haven't tried Monitor, that could be better, but as another option I've been using my own little function for that forever:

pdr[expr_, symbols_List : {}, interval_ : Infinity] := 
 PrintTemporary[
  Dynamic[Refresh[expr, TrackedSymbols :> symbols, 
    UpdateInterval -> interval]]]

Before my code I use e.g. pdr[x,{x}], which shows x and updates whenever it does, or pdr[ListLinePlot[data],{},5] which updates a plot every 5 seconds, or whatever. It disappears when the block is done running.

POSTED BY: Trevor Cappallo

There is also Dynamic:

Dynamic[count]

For[count=1,count<=5000, count++,  pass]  
POSTED BY: W. Craig Carter

Hans suggestion hits the bullseye, but Also consider PrintTemporary. It is not exactly what you asked for but it is useful as well for monitoring progress.

Regards,

Neil

POSTED BY: Neil Singer
Posted 3 years ago

Thanks. Looks like exactly what I want ...

POSTED BY: David Golber
Posted 3 years ago

Check out Monitor

POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract