Suppress Warnings
Your program might issue warnings that do not always adversely affect execution. To
avoid confusion, you can hide warning messages during execution by changing their
states from 'on' to 'off'.
To suppress specific warning messages, you must first find the warning identifier. Each
warning message has a unique identifier. To find the identifier associated with a MATLAB
warning, reproduce the warning. For example, this code reproduces a warning thrown if
MATLAB attempts to remove a nonexistent folder:
rmpath('folderthatisnotonpath')
Warning: "folderthatisnotonpath" not found in path.
NoteIf this statement does not produce a warning message, use the following code to
temporarily enable the display of all warnings, and then restore the original warning
state:
w = warning ('on','all');
rmpath('folderthatisnotonpath')
warning(w)
To obtain information about the most recently issued warning, use the warning or
lastwarn functions. This code uses the query state to return a data structure containing
the message identifier and the current state of the last warning:
w = warning('query','last')
w =
identifier: 'MATLAB:rmpath:DirNotFound'
state: 'on'
You can save the identifier field in the variable, id:
id = w.identifier;
Notewarning('query','last') returns the last displayed warning. MATLAB only
displays warning messages that have state: 'on' and a warning identifier.
26 Error Handling