warn_test

Test for (suppressed) Matlab warning message

Syntax

   [waswarn,msgstr,warnid] = warn_test(oldstate, false)
   [waswarn,msgstr,warnid] = warn_test(oldstate, warnmsg, warnfunc,rwarnid)

Arguments

input

   oldstate   old warning state to restore (required)
   warnmsg    string specifying (user-supplied) warning message (or 'false' to suppress warning)
   warnfunc   string specifying which function issued the warning
   rwarnid    report Matlab warning identifier

output

   waswarn    true if a warning was issued
   msgstr     warning message
   warnid     warning Matlab warning identifier

Description

Tests for Matlab warning suppressed by warn_supp; see also warning. After testing, the previous warning state (as returned by warn_supp) is restored.

The warn_supp ... warn_test routines exist for two reasons: (1) if routines issuing warnings are run in a loop (which they frequently are in the MVGC Toolbox), Matlab will by default spew confusing warnings, obscuring meaningful ouput; (2) we want to be able to issue meaningful context-dependent warning messages.

If warnmsg is a logical flag set to false, reporting of warning messages is suppressed (presumably the user will handle warnings based on the return values). Otherwise, warnmsg is interpreted as a user-defined warning message to report; if empty (default), the Matlab warning message is reported. A string specifying which function issued the warning may be supplied in warnfunc - if not present it defaults to the enclosing function. If the flag rwid is set, the Matlab warining identifier is reported (default: false).

Example

   A = magic(6);
   oldstate = warn_supp('MATLAB:nearlySingularMatrix');
   B = inv(A);
   warn_test(oldstate,'badly-conditioned matrix?');

See also

warning | warn_supp | warn_if | startup