Array indices must be positive integers or logical values.
5 views (last 30 days)
Show older comments
I am not sure why my code is coming up with this:
Array indices must be positive integers or logical values.
Error in P9_07_Casey_Galerneau (line 18)
monthly =
principal*((interest(1+interest)^number_payments)/((1+interest)^number_payments)-1);
>>
8 Comments
Walter Roberson
on 23 Apr 2018
"for" must be followed in the same line by something in the form of an assignment.
Answers (1)
Walter Roberson
on 23 Apr 2018
interest(1+interest) attempts to index the vector or array interest at location(s) 1+interest . That is not necessarily impossible -- for example if interest = [0 1 2] then 1+interest would be 1 2 3 and interest([1 2 3]) would be valid. It is, however, rather suspect.
You should probably recheck your formula to see whether the formula asked for indexing at that point, or asked for multiplication.
2 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!