How to Set Warning Message Modes in MATLAB - dummies

How to Set Warning Message Modes in MATLAB

By Jim Sizemore, John Paul Mueller

Error messages always provide you with any details that the application provides. Warning messages are different — you can tell MATLAB to provide only certain details as needed. You can set the configuration globally or base it on the message identifier (so that warnings with some identifiers provide more information than others do). To set the global configuration, you provide two arguments. The first is the warning state:

  • on: Sets the configuration element on.

  • off: Turns the configuration element off.

  • query: Determines whether the configuration element is currently on or off.

At a global level, you have access to two settings, which are provided as the second argument to the warning() function:

  • backtrace: Determines whether the output includes stack trace information.

  • verbose: Determines whether the output includes a short message or one with all the details as well.

To see how this works, type warning(‘query’, ‘backtrace’) and press Enter. You should see an output message telling you the current status of the backtrace configuration element. (The default setting turns it on so that you can see the stack trace as part of the warning message when a stack trace is provided.)

The message identifier-specific form of the warning() function starts with a state. However, in this case, the second argument is a message identifier. For example, if you type warning(‘query’, ‘MATLAB:FileIO:InvalidFid’) and press Enter, you see the current state of the MATLAB:FileIO:InvalidFid identifier.

Setting warnings for particular message identifiers to off is usually a bad idea because the system can’t inform you about problems. This is especially true for MATLAB-specific messages (rather than custom messages that you create). However, setting them to off during troubleshooting can help you avoid the headache of seeing the message all the time.