Troubleshooting Matlab

This page summarizes common errors.

Masking Built-in Functions

Matlab permits you to redefine anything, which can lead to unexpectedly masking basic functionality. For example:

    » sum(0:25)

    ans =

       325

    » sum = 0

    sum =

         0

    » sum(0:25)
    ??? Index into matrix is negative or zero.

    » 
The problem is that when you say "sum = 0" you have redefined "sum"! If you type the line "sum(0:25)" only long after you have redefined sum, you might be very confused. How could this basic Matlab function not work? Typing "help sum" will only make this confusion worse, since every careful reading of the information it gives you indicates that sum(0:25) will work. The fix is:
    » clear sum
    » sum(0:25)

    ans =

       325

    »