How can I flush the output of disp in Matlab or Octave?

Use fflush(stdout) and/or fflush(stderr) to flush the buffer from disp().


As mentioned by moastab, fflush(stdout) works for Octave.

In MATLAB, use drawnow('update') to flush the output.

MATLAB's drawnow function will be familiar to those who control the redrawing of graphical objects in MATLAB, but it applies to the stdout stderr buffers as well. The 'update' option is not required, but limits the flushing to non-graphical queues. This detail is merely implied in the drawnow() documentation; I have verified it to work on fprintf calls in a loop.