print to stderr from Matlab / GNU Octave

less than 1 minute read

In both Matlab and GNU Octave, functions like error and warning by default print messages to stderr in non-interactive sessions, for easier capture to uncluttered log files.

To print to stderr in general, use

fprintf(2, 'my text')

Examples

You can verify these are printing to stderr by appending to the end of the command line command: 2>err.log

  • octave-cli --eval "fprintf(2,'this is stderr')"
  • matlab -nojvm -r "fprintf(2,'this is stderr'); exit"

Leave a comment