It may be that you have a local variable called sum that is shadowing the MATLAB sum function. Try clearing it first:
clear sum
And then avoid using sum as a variable name in the future.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!