For loop Technical Question

12 views (last 30 days)
Hello, I am working on a project for a class, but keep running into a technical error that occurs every time I try to create a matrix using for loops. I do not know if my syntax is incorrect, but the value of m should never be negative while in the for loop, so I do not know why I keep getting "Subscript indices must either be real positive integers or logicals." Attached is my script and the error message with it. I can debug the matrix to input the right values myself, but I just need help getting over this error.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Apr 2018
h is a scalar. h(dX^2) is an attempt to index that scalar at the location computed by squaring dX. If dX does not happen to be exactly 1, then the result of dX^2 is not going to be a valid index into the scalar.
Remember that MATLAB does not have implicit multiplication: if you want multiplication you need to code multiplication.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!