Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a program in Octave that has a loop - running a function with various parameters, not something that I can turn into matrices. At the beginning of each iteration I print the current parameters using disp.

The first times I ran it I had a brazillion warnings, and then I also got these prints. Now that I cleaned them up, I no longer see them. My guess is that they're stuck in a buffer, and I'll see them when the program ends or the buffer fills.

Is there any way to force a flush of the print buffer so that I can see my prints?

like image 774
Nathan Fellman Avatar asked Apr 13 '10 20:04

Nathan Fellman


4 Answers

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

like image 151
moastab Avatar answered Nov 10 '22 10:11

moastab


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.

like image 33
Arthur Hebert-Ryan Avatar answered Nov 10 '22 09:11

Arthur Hebert-Ryan


Octave: You can turn off buffering of output by calling more off.

This will disable pagination such that all output is sent directly to the screen.

like image 20
Micke Avatar answered Nov 10 '22 08:11

Micke


Put the following commands at the beginning of your section or your code:

page_screen_output(0);

page_output_immediately(1);
like image 7
Charles Valente Avatar answered Nov 10 '22 10:11

Charles Valente