Why can't Matlab calculate a(0)
3 views (last 30 days)
Hi everyone, its not serious problem at all. But I just want to know. Why cant Matlab calculate a(0) in a for loop.
>> ai=[2 4 6 8];
Matlab will give an error message that says
"Attempted to access (0); index must be a positive integer or
My question is why?? I get results if I use
because a(1) , a(2) etc can be found in matlab. so why not a(0)???
More Answers (1)
Walter Roberson on 4 Feb 2013
You need to distinguish between array notation and function notation.
Array notation requires that the arguments describe integer array locations. Array locations in MATLAB are numbered starting from 1, as is the case for Fortran and a number of other computer languages (but not all -- e.g., C numbers starting from 0.)
function notation is what is used when you say things like
f(1.37) = 8.2
an(0) = 4
That notation is completely valid in mathematics, but it has no equivalent in MATLAB, except inside MuPAD (the symbolic toolbox).