简体   繁体   English

如何抑制GNU八度音程中的警告

[英]How to suppress warnings in GNU octave

I am using Octave version 3.4.3, and I get this warning: 我正在使用Octave版本3.4.3,我收到此警告:

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

But that disables all warnings which is bad form. 但是这会禁用所有不良形式的警告。 How to disable only this one? 如何只禁用这个?

Disable warnings by warning type in GNU Octave: 在GNU Octave中通过警告类型禁用警告:

See the list of warnings and their warning id's and names here in section: '12.2.2 Enabling and Disabling Warnings'. 请参阅以下部分中的警告列表及其警告ID和名称:'12 .2.2启用和禁用警告'。 https://octave.sourceforge.io/octave/function/warning_ids.html https://octave.sourceforge.io/octave/function/warning_ids.html

The warning names and id's are listed with octave command: 使用octave命令列出警告名称和ID:

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. 例如,使用octave yourfile.m 2>/dev/null ,这也有重定向八度引擎和脚本的stderr的不幸副作用。

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. 要解决此问题,请将/home/el/octave/multicore-0.2.15/gethostname.m重命名为/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. 这是软件中的一个错误,其中两个文件具有相同的名称,因此程序不知道使用哪个文件。

To find out the ID of your warning, just issue 要找出警告的ID,请发布

[text, id] = lastwarn()

directly after the warning occurs. 警告发生后直接发生。 id now contains the id of the warning, which can be used to switch it off: id现在包含警告的id,可用于将其关闭:

warning('off', id)

Make your changes persistent in two easy steps: 通过两个简单的步骤使您的更改持久化:

  1. become root 成为根
  2. append command to the file (/usr/share/octave/site/m/startup/octaverc), which will execute any Octave commands at startup. 将命令附加到文件(/ usr / share / octave / site / m / startup / octaverc),它将在启动时执行任何Octave命令。

    echo "warning('off','Octave:shadowed-function')" >> /usr/share/octave/site/m/startup/octaverc

I also like to persitantly autoload all packages: 我也喜欢坚持自动加载所有包:

echo "pkg load all" >> /usr/share/octave/site/m/startup/octaverc

Note: Follow this order, otherwise any shadowed-function warnings you get from loading all packages will still appear. 注意:请遵循此顺序,否则仍会显示从加载所有包中获得的任何阴影功能警告。

your file should now contain 您的文件现在应该包含

warning('off','Octave:shadowed-function')
pkg load all

Thanks to Gunther Struyf , for telling us how to turn off shadowed function warnings (above). 感谢Gunther Struyf ,告诉我们如何关闭阴影功能警告(上图)。 Reference: https://wiki.archlinux.org/index.php/Octave 参考: https//wiki.archlinux.org/index.php/Octave

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM