Essential MATLAB for Engineers and Scientists, Third Edition

The objective of this chapter is to enable you to:
Begin to recognize and avoid different sorts of errors and pitfalls.
Even experienced programmers seldom get programs to run correctly the first time. In computer jargon, an error in a program is called a bug. The story is that a hapless moth short-circuited two thermionic valves in one of the earliest computers. This primeval (charcoaled) bug took days to find. The process of detecting and correcting such errors is therefore called debugging. There are a number of different types of errors and pitfalls, some of which are peculiar to MATLAB, and some of which may occur when programming in any language. These are discussed briefly in this chapter.
Syntax errors are typing errors in MATLAB statements (e.g. plog instead of plot). They are the most frequent type of error, and are fatal: MATLAB stops execution and displays an error message. Since MATLAB is not even remotely as intelligent as you are, the messages can sometimes be rather unhelpful even misleading. A few common examples are given below.
")" expected, "end of line" found.
This is generated in response to something like
2*(1+3
What could possibly be more helpful than that?
You also get this message, quite properly, after something like
disp(['the answer is ' num2str(2)]
because the closing right parenthesis has been omitted. However, if you omit the closing square bracket instead, you get the somewhat unhelpful ";" expected, ")" found.