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, 'Hello text')

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

From GNU Octave:

octave-cli --eval "fprintf(2,'this is stderr')"

From Matlab:

matlab -batch "fprintf(2,'this is stderr')"