| GNU Octave Manual Version 3 by John W. Eaton, David Bateman, Søren Hauberg Paperback (6"x9"), 568 pages ISBN 095461206X RRP £24.95 ($39.95) |
12.2.2 Enabling and Disabling Warnings
The warning function also allows you to control which warnings
are actually printed to the screen. If the warning function
is called with a string argument that is either "on" or "off"
all warnings will be enabled or disabled.
It is also possible to enable and disable individual warnings through their string identifications. The following code will issue a warning
warning ("non-negative-variable",
"'a' must be non-negative. Setting 'a' to zero.");
while the following won't issue a warning
warning ("off", "non-negative-variable");
warning ("non-negative-variable",
"'a' must be non-negative. Setting 'a' to zero.");
The functions distributed with Octave can issue one of the following warnings.
Octave:array-to-scalar-
If the
Octave:array-to-scalarwarning is enabled, Octave will warn when an implicit conversion from an array to a scalar value is attempted. By default, theOctave:array-to-scalarwarning is disabled. Octave:array-to-vector-
If the
Octave:array-to-vectorwarning is enabled, Octave will warn when an implicit conversion from an array to a vector value is attempted. By default, theOctave:array-to-vectorwarning is disabled. Octave:assign-as-truth-value-
If the
Octave:assign-as-truth-valuewarning is enabled, a warning is issued for statements likeif (s = t) ...
since such statements are not common, and it is likely that the intent was to writeif (s == t) ...
instead. There are times when it is useful to write code that contains assignments within the condition of awhileorifstatement. For example, statements likewhile (c = getc()) ...
are common in C programming. It is possible to avoid all warnings about such statements by disabling theOctave:assign-as-truth-valuewarning, but that may also let real errors likeif (x = 1) # intended to test (x == 1)! ...
slip by. In such cases, it is possible suppress errors for specific statements by writing them with an extra set of parentheses. For example, writing the previous example aswhile ((c = getc())) ...
will prevent the warning from being printed for this statement, while allowing Octave to warn about other assignments used in conditional contexts. By default, theOctave:assign-as-truth-valuewarning is enabled. Octave:associativity-change-
If the
Octave:associativity-changewarning is enabled, Octave will warn about possible changes in the meaning of some code due to changes in associativity for some operators. Associativity changes have typically been made for Matlab compatibility. By default, theOctave:associativity-changewarning is enabled. Octave:divide-by-zero-
If the
Octave:divide-by-zerowarning is enabled, a warning is issued when Octave encounters a division by zero. By default, theOctave:divide-by-zerowarning is enabled. Octave:empty-list-elements-
If the
Octave:empty-list-elementswarning is enabled, a warning is issued when an empty matrix is found in a matrix list. For example,a = [1, [], 3, [], 5]
By default, theOctave:empty-list-elementswarning is enabled. Octave:fortran-indexing-
If the
Octave:fortran-indexingwarning is enabled, a warning is printed for expressions which select elements of a two-dimensional matrix using a single index. By default, theOctave:fortran-indexingwarning is disabled. Octave:function-name-clash-
If the
Octave:function-name-clashwarning is enabled, a warning is issued when Octave finds that the name of a function defined in a function file differs from the name of the file. (If the names disagree, the name declared inside the file is ignored.) By default, theOctave:function-name-clashwarning is enabled. Octave:future-time-stamp-
If the
Octave:future-time-stampwarning is enabled, Octave will print a warning if it finds a function file with a time stamp that is in the future. By default, theOctave:future-time-stampwarning is enabled. Octave:imag-to-real-
If the
Octave:imag-to-realwarning is enabled, a warning is printed for implicit conversions of complex numbers to real numbers. By default, theOctave:imag-to-realwarning is disabled. Octave:matlab-incompatible- Print warnings for Octave language features that may cause compatibility problems with Matlab.
Octave:missing-semicolon-
If the
Octave:missing-semicolonwarning is enabled, Octave will warn when statements in function definitions don't end in semicolons. By default theOctave:missing-semicolonwarning is disabled. Octave:neg-dim-as-zero-
If the
Octave:neg-dim-as-zerowarning is enabled, print a warning for expressions likeeye (-1)
By default, theOctave:neg-dim-as-zerowarning is disabled. Octave:num-to-str-
If the
Octave:num-to-strwarning is enable, a warning is printed for implicit conversions of numbers to their ASCII character equivalents when strings are constructed using a mixture of strings and numbers in matrix notation. For example,[ "f", 111, 111 ] => "foo"
elicits a warning if theOctave:num-to-strwarning is enabled. By default, theOctave:num-to-strwarning is enabled. Octave:precedence-change-
If the
Octave:precedence-changewarning is enabled, Octave will warn about possible changes in the meaning of some code due to changes in precedence for some operators. Precedence changes have typically been made for Matlab compatibility. By default, theOctave:precedence-changewarning is enabled. Octave:reload-forces-clear-
If several functions have been loaded from the same file, Octave must
clear all the functions before any one of them can be reloaded. If
the
Octave:reload-forces-clearwarning is enabled, Octave will warn you when this happens, and print a list of the additional functions that it is forced to clear. By default, theOctave:reload-forces-clearwarning is enabled. Octave:resize-on-range-error-
If the
Octave:resize-on-range-errorwarning is enabled, print a warning when a matrix is resized by an indexed assignment with indices outside the current bounds. By default, theOctave:resize-on-range-errorwarning is disabled. Octave:separator-insert- Print warning if commas or semicolons might be inserted automatically in literal matrices.
Octave:single-quote-string- Print warning if a single quote character is used to introduce a string constant.
Octave:str-to-num-
If the
Octave:str-to-numwarning is enabled, a warning is printed for implicit conversions of strings to their numeric ASCII equivalents. For example,"abc" + 0 => 97 98 99
elicits a warning if theOctave:str-to-numwarning is enabled. By default, theOctave:str-to-numwarning is disabled. Octave:string-concat-
If the
Octave:string-concatwarning is enabled, print a warning when concatenating a mixture of double and single quoted strings. By default, theOctave:string-concatwarning is disabled. Octave:undefined-return-values-
If the
Octave:undefined-return-valueswarning is disabled, print a warning if a function does not define all the values in the return list which are expected. By default, theOctave:undefined-return-valueswarning is enabled. Octave:variable-switch-label-
If the
Octave:variable-switch-labelwarning is enabled, Octave will print a warning if a switch label is not a constant or constant expression. By default, theOctave:variable-switch-labelwarning is disabled.
| ISBN 095461206X | GNU Octave Manual Version 3 | See the print edition |