views:

376

answers:

3

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?

+1  A: 

If I understand your question correctly, you can use diary function to dump all session output to a text file. diary on will start recording, and diary off will stop. diary filename will use filename instead of default "diary".

It is build -in function in both Octave and MATLAB. For more details see help diary.


Also you can increase Octave buffer size. On Windows you can do it in Octave Properties dialog from upper left corner menu.

yuk
A: 

drawnow will cause graphs to update, I'm not sure if it works on the stdout pipe as well.

You might also convert your disp(...) statements to fprintf(stderr, ...), I think stderr is handled differently from stdout on Octave.

mtrw
+2  A: 

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

moastab
Out of curiosity, do you know if there's a Matlab equivalent to fflush()? I'd like to do the same thing, but I use Matlab, not Octave, and there's no fflush() function.
Andrew Janke

related questions