MATLAB: “roots” function not working

roots

Hi,
I need to use the roots function to find the roots of a polynomial. I copied the text from the example @ the MathWorks.com entry for this function:
p = [1 -6 -72 -27];
r = roots(p);
However, r does not return, and the following error appears:
??? Subscript indices must either be real positive integers or logicals.
I cannot believe that Matlab cannot execute this simple code that is an official example. Does someone have any insight as to what the problem may be?

Best Answer

You have a variable named roots. Do this :
clear roots
p = [1 -6 -72 -27];
r = roots(p);
Don't name variables after built-in MATLAB functions. (And especially don't blame MATLAB for your silly mistakes ;-))