A Guide to MATLAB for Beginners and Experienced Users

Chapter 11: Troubleshooting

In this chapter, we offer advice for dealing with some common problems that you may encounter. We also list and describe the most common mistakes that MATLAB users make. Finally, we offer some simple but useful techniques for debugging your M-files.

Common Problems

Problems manifest themselves in various ways: Totally unexpected or plainly wrong output appears; MATLAB produces an error message (or at least a warning); MATLAB refuses to process an input line; something that worked earlier stops working; or, worst of all, the computer freezes. Fortunately, these problems are often caused by several easily identifiable and correctable mistakes. What follows is a description of some common problems, together with a presentation of likely causes, suggested solutions, and illustrative examples. We also refer to places in the book where related issues are discussed.

Here is a list of the problems:

  • wrong or unexpected output,

  • syntax error,

  • spelling error,

  • error messages when plotting,

  • a previously saved M-file evaluates differently, and

  • computer won't respond.

Wrong or Unexpected Output

There are many possible causes for this problem, but they are likely to be among the following:

CAUSE: Forgetting to clear or reset variables.

SOLUTION: Clear or initialize variables before using them, especially in a long session.

Note

See Variables and Assignments in Chapter 2.

CAUSE: Conflicting definitions.

SOLUTION: Do not use the same name for two different functions or variables, and in particular, try not to overwrite the names of any of MATLAB's built-in functions.

You can accidentally mask...

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: Spectrum Analyzers and Signal Analyzers
Finish!
Privacy Policy

This is embarrasing...

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