1

There is something very simple that can be very upsetting occasionally.

I sometimes want to keep track of the outputs of an algorithm at each iteration, so within a for loop, I use disp command of MATLAB to output some information. However, although there is quite a bit of time between the calling of dispcommands, the MATLAB command window falls behind and I need to use the mouse to keep up with it manually. Do you know if there is any way to have it not fall behind?

Thanks,

2
  • Out of curiosity, did you find a solution, like the short pause I suggested? Commented Dec 9, 2013 at 19:29
  • Yes! The short pause before dispcommand solved the issue. Thanks a lot. Commented Dec 10, 2013 at 12:54

2 Answers 2

3

It really shouldn't fall behind, but I could see this happening if the computations are intensive and the MATLAB JVM, which drives the GUI, does get the resources to update the command window.

The following command may be of help:

drawnow update % or just drawnow

According to the documenatation page, this "causes only user-interface objects to refresh, if needed". If that fails, try just drawnow with no arguments to see if it helps to flush the entire system event queue, including graphics updates.

If that doesn't work you could insert a pause(0.01) or something similar as a last resort.

Sign up to request clarification or add additional context in comments.

3 Comments

Not that there's really a difference, but I prefer to use the function form in code: drawnow('update');.
Unfortunately it does not flush the command prompt. However this is a very useful command.
Oh well. But I'd be willing to bet a pause(0.01) or similar would do the trick.
1

It shouldn't fall behind if you don't use the mouse at all. However, I often use the waitbar for this purpose.

FEX also has several text & GUI progress bars.

1 Comment

I'd guess that waitbar has an implicit call to drawnow within it that would flush command window content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.