23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Warnings<br />

Message Identifiers<br />

Use a message identifier argument with warning to attach a unique tag to<br />

that warning message. <strong>MATLAB</strong> uses this tag to better identify the source of<br />

a warning. The first argument in this example is the message identifier.<br />

warning('<strong>MATLAB</strong>:paramAmbiguous', ...<br />

'Ambiguous parameter name, "%s".', param)<br />

See “Warning Control Statements” on page 8-17 for more information on<br />

how to use identifiers with warnings.<br />

Identifying the Cause<br />

The lastwarn function returns a string containing the last warning message<br />

issued by <strong>MATLAB</strong>. You can use this to enable your program to identify the<br />

cause of a warning that has just been issued. To return the most recent<br />

warning message to the variable warnmsg, type<br />

warnmsg = lastwarn;<br />

You can also change the text of the last warning message with a new message<br />

or with an empty string as shown here.<br />

lastwarn('newwarnmsg');<br />

lastwarn('');<br />

% Replace last warning with new string<br />

% Replace last warning with empty string<br />

8-15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!