MATLAB: Error with indices and vectors

vectors

i= 7.5;
A= 300000;
P= 8000;
n=[6:6:60]';
B= A(1+i/12).^n-(P/(i/12)).*((1+i/12).^n-1);
table(n, B)
Array indices must be positive integers or logical values.
can someone help me with this error please?

Best Answer

MATLAB has no implied multiplication.
A(1+i/12) is syntactically always either a request to execute a function indicated by A with parameter 1+i/12, or else a request to index array A at location 1+i/12 .
As we can see a definition for the variable A, we know that in this case it must be a request to index A at 1+i/12 . But i is 7.5 and 1+i/12 will definitely not be a positive integer, so that is not valid indexing.
If you want to multiply A and (1+i/12) then you need to explicitly multiply, using either the .* or * operator.