print to stderr from Matlab / GNU Octave

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')


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 -batch "fprintf(2,'this is stderr')"