Why do I get this error?

조회 수: 5 (최근 30일)
Hdez
Hdez 2021년 1월 22일
답변: William 2021년 1월 22일
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Error in Code2 (line 61)
T2(i,j)= (T1(i-1,j)+ T1(i-1,j)+T1(i,j+1)+T1(i,j-1)-(4-1/fo)*T1(i,j))*fo

답변 (1개)

William
William 2021년 1월 22일
One of the first two terms on the right should have an i+1 rather than i-1, but this is undoubtedly not the problem that caused the error message. The code will probably work for most values of i and j, but it has problems at the borders of the array T1(). For example, for i=1, the first term evaluates to T1(0,j), and you can't have a subscript of zero. Likewise, at the maximum value imax of i, the subscripts should evaluation to T1(imax+1,j), and this will be out of bounds for the array. The same applies to the bordering values for j. So, in this type of expression, you have to treat the edges of the arrays separately.

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by