For loop Technical Question

조회 수: 12 (최근 30일)
Alec Betancourt
Alec Betancourt 2018년 4월 22일
댓글: Alec Betancourt 2018년 4월 22일
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.

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 22일
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.
  댓글 수: 1
Alec Betancourt
Alec Betancourt 2018년 4월 22일
Thank you, You are a saint.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by