필터 지우기
필터 지우기

Index in position 2 exceeds array bounds (must not exceed 10)

조회 수: 3 (최근 30일)
Iman Hana Mustafa Kamal
Iman Hana Mustafa Kamal 2019년 3월 1일
편집: Iman Hana Mustafa Kamal 2019년 3월 2일
Please help me debug this. I commented the line that Matlab says has error.
The error says this: Index in position 2 exceeds array bounds (must not exceed 10). I know it means my array does not match somehow but cant figure it out.
Any help is appreciated. Thanks!
for i = 1:10
if 1 == 10
ttr = 2.6366*10^(-4) * k * (lambda_w (n,i) + lambda_o (n,i))* dydz / D;
twr = 2.6366*10^(-4) * k * (lambda_w (n,i))* dydz / D;
sw (n+1,i) = (1+ (cr+cw) * (po (n+1,i) - po (n,i))) * sw (n,i) + (t_step / (VR * phi)) * ...
(-twr * (po(n+1,i) - po(n+1,i-1)) + twl * (pcow(n,i) - pcow(n,i-1)) + q(n,i));
else
ttl = ttr;
twl = twr;
ttr = 2.6366*10^(-4) * k * (lambda_w (n,i) + lambda_o (n,i))* dydz / D;
twr = 2.6366*10^(-4) * k * (lambda_w (n,i))* dydz / D;
sw (n+1,i) = (1+ (cr+cw) * (po(n+1,i) - po(n,i))) * sw (n,i) + (t_step / (VR * phi)) * ...
(twr * (po(n+1,i+1) - po(n+1,i)) - twl * (po(n+1,i) - po(n+1,i-1)) - twr * (pcow(n,i+1) - pcow(n,i)) ...
+ twl * (pcow(n,i) - pcow(n,i-1))); %%%%%%%%%%%%%% this line is the problem %%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end

답변 (1개)

KSSV
KSSV 2019년 3월 1일
편집: KSSV 2019년 3월 1일
YOu should not run loop i from 1 to 10. All your arrays are size 2*10 and you are using n+1 in the code....so for i = 10, the index becomes 11 and it throws error. Try running loop from i = 1:9.

카테고리

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