MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Using the lastwarn function, you can retrieve the last warning message, regardless of
its display state:


lastwarn


ans =


"folderthatisnotonpath" not found in path.


Turn Warnings On and Off


After you obtain the identifier from the query state, use this information to disable or
enable the warning associated with that identifier.


Continuing the example from the previous section, turn the warning
'MATLAB:rmpath:DirNotFound' off, and repeat the operation.


warning('off',id)
rmpath('folderthatisnotonpath')


MATLAB displays no warning.


Turn the warning on, and try to remove a nonexistent path:


warning('on',id)
rmpath('folderthatisnotonpath')


Warning: "folderthatisnotonpath" not found in path.


MATLAB now issues a warning.


TipTurn off the most recently invoked warning with warning('off','last').


Controlling All Warnings


The term all refers only to those warnings that have been issued or modified during your
current MATLAB session. Modified warning states persist only through the current
session. Starting a new session restores the default settings.


Use the identifier 'all' to represent the group of all warnings. View the state of all
warnings with either syntax:


Suppress Warnings
Free download pdf