A buggy example

Here is a short script called buggy.m

When we run this script (by typing in buggy at the MATLAB prompt), this is what happens:

MATLAB is trying to tell us that there is a bug (an error) in our script buggy.m.
MATLAB even tells us where it thinks the error is: Line 9, Column 7.

Sure enough, there is an error: an extra * at the end of the line. MATLAB does not like extra asterisks hanging around. Note that even though the error does not occur until Line 9, none of the lines in the buggy.m script produce any output.

After we edit buggy.m to remove that extra asterisk at the end of Line 9, then we run buggy.m again, with these results:

It looks like there's another bug, but this time MATLAB executed all the statements before this bug and printed out the results. Let's have a look at line 17:

Comment out this line and run buggy.m again - you'll see that all the bugs are now fixed!

Take-home lesson: bugs in MATLAB scripts often suppress output entirely, so carefully check your code for errors. Alternatively, you can comment out the buggy line(s) and rerun your code.