Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress warnings in GNU octave

I am using Octave version 3.4.3, and I get this warning:

warning: fmincg.m: 
possible Matlab-style short-circut operator at line 104, column 20

I know why this warning occurs, I just want to make the warning not appear on screen when run.

I know I can suppress ALL warnings by putting this command at the top of my octave program:

warning('off','all');

Docs: https://octave.sourceforge.io/octave/function/warning.html

But that disables all warnings which is bad form. How to disable only this one?

like image 391
Eric Leschinski Avatar asked Jul 08 '12 15:07

Eric Leschinski


People also ask

How do I turn off the warning message in Matlab?

You can suppress all warning messages using the 'off' state option, with the argument 'all' in place of a message identifier. You can suppress only the last warning message in a similar manner, replacing 'all' with 'last'.

How do I turn off warnings in Python?

If you're on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int. (Note that in Python 3.2, deprecation warnings are ignored by default.) This is especially useful to ignore warnings when performing tests.


1 Answers

Disable warnings by warning type in GNU Octave:

See the list of warnings and their warning id's and names here in section: '12.2.2 Enabling and Disabling Warnings'. https://octave.sourceforge.io/octave/function/warning_ids.html

The warning names and id's are listed with octave command:

help warning_ids

Put this command in your octave program before the warning occurs:

warning('off', 'Octave:possible-matlab-short-circuit-operator');

or disable all warnings with

warning('off', 'all');

Note: If your warning is thrown by the octave interpreter itself before your script is run, then you'll have to take a different approach. For example use octave yourfile.m 2>/dev/null which also has the unfortunate side effect of redirecting the stderr of both the octave engine and your script.

Certain warnings terminate the process, and can't be suppressed, they must be remedied:

Like this one:

warning: function /home/el/octave/multicore-0.2.15/gethostname.m 
         shadows a built-in function

To fix this, rename /home/el/octave/multicore-0.2.15/gethostname.m to /home/el/octave/multicore-0.2.15/gethostname_backup.m. And the warning goes away. It's a bug in the software where two files have the same name, so the program doesn't know which one to use.

like image 58
Eric Leschinski Avatar answered Sep 16 '22 18:09

Eric Leschinski