warning function alerts the user of unexpected conditions detected when running a program. However,
warning does not halt the execution of the program. It displays the specified warning message and then continues.
Reporting a Warning
warning in your code to generate a warning message during execution. Specify the message string as the input argument to
warning. For example,
Warnings also differ from errors in that you can disable any warnings that you don't want to see. You do this by invoking
warning with certain control parameters. See Warning Control for more information.
Formatted Message Strings
The warning message string that you specify can also contain formatting conversion characters, such as those used with the MATLAB
sprintf function. Make the warning string the first argument, and then add any variables used by the conversion as subsequent arguments.
For example, if your program cannot process a given parameter, you might report a warning with
MATLAB converts special characters (like
%d) in the warning message string only when you specify more than one input argument with
warning. See Formatted String Conversion for information.
Use a message identifier argument with
warning to attach a unique tag to that warning message. MATLAB uses this tag to better identify the source of a warning. The first argument in this example is the message identifier.
See Warning Control Statements for more information on how to use identifiers with warnings.
Identifying the Cause
lastwarn function returns a string containing the last warning message issued by MATLAB. You can use this to enable your program to identify the cause of a warning that has just been issued. To return the most recent warning message to the variable
You can also change the text of the last warning message with a new message or with an empty string as shown here.
|Using Message Identifiers with lasterr||Warning Control|
© 1994-2005 The MathWorks, Inc.