MATLAB Guide

Chapter 14: Troubleshooting

14.1 Errors and Warnings

Errors in MATLAB are of two types: syntax errors and runtime errors. A syntax error is illustrated by

   <span class="unicode">?</span> for i=1#10, x(i) = 1/i; end   ??? for i=1#10, x(i) = 1/i; end                 Error: Missing variable or function.

Here a # has been typed instead of a colon and the error message pinpoints where the problem occurs. If an error occurs in an M-file then the name of the M-file and the line on which the error occurred are shown. If you move the cursor onto the error message and press the enter key then the M-file is opened in the MATLAB Editor/Debugger (see Section 7.2) and the cursor is placed on the line containing the error.

A runtime error occurs with the script fib in Listing 14.1. The loop should begin at i = 3 to avoid referencing x(0). When we run the script, MATLAB produces an informative error message:

   <span class="unicode">?</span> fib   ??? Index into matrix is negative or zero.   Error in ==> FIB.M   On line 4 ==> x(i) = x(i-1) + x(i-2);

When an error occurs in a nested sequence of M-file calls, the history of the calls is shown in the error message. The first " Error in" line is the one describing the M-file in which the error is located.

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Error Correction Chips
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.