Main Content

Change How Warnings Display

You can control how warnings appear in MATLAB® by modifying two warning modes, verbose and backtrace.

Mode

Description

Default

verbose

Display a message on how to suppress the warning.

off (terse)

backtrace

Display a stack trace after a warning is invoked.

on (enabled)

Note

The verbose and backtrace modes present some limitations:

  • prev_state does not contain information about the backtrace or verbose modes in the statement, prev_state = warning('query','all').

  • A mode change affects all enabled warnings.

Enable Verbose Warnings

When you enable verbose warnings, MATLAB displays an extra line of information with each warning that tells you how to suppress it.

For example, you can turn on all warnings, disable backtrace, and enable verbose warnings:

warning on all
warning off backtrace
warning on verbose

Running a command that produces an error displays an extended message:

rmpath('folderthatisnotonpath')
Warning: "folderthatisnotonpath" not found in path.
(Type "warning off MATLAB:rmpath:DirNotFound" to suppress this warning.) 

Display a Stack Trace on a Specific Warning

It can be difficult to locate the source of a warning when it is generated from code buried in several levels of function calls. When you enable the backtrace mode, MATLAB displays the file name and line number where the warning occurred. For example, you can enable backtrace and disable verbose:

warning on backtrace
warning off verbose

Running a command that produces an error displays a hyperlink with a line number:

Warning: "folderthatisnotonpath" not found in path. 
> In rmpath at 58 

Clicking the hyperlink takes you to the location of the warning.