Index in position 2 exceeds array bounds

I got this error, what does it mean and how can i fix it?
"Index in position 2 exceeds array bounds (must not exceed 2)."
this is the code of the line:
I(temp,:) = [zeros(1,temp-2) -1/(mul*Capacitance(1,temp-1)) 1/(mul*Capacitance(1,temp-1))+1/(mul*Capacitance(1,temp))+mul*inductance(1,temp) -1/(mul*Capacitance(1,temp)) zeros(1,length(inductance)-1-temp)];

댓글 수: 3

James Tursa
James Tursa 2020년 11월 24일
Terminology: If you have a subscripted variable:
A(i,j,k)
Then the index in position 1 is i, and the index in position 2 is j, and the index in position 3 is k, etc.
So in your case one of the 2nd indexes you used is larger than the variable size in the 2nd dimension. Maybe temp is too big for Capacitance or inductance.
You fix it by going back to your original equations and then coding them up properly according to the actual sizes of your variables.
Nora Khaled
Nora Khaled 2020년 11월 24일
Its hard to tell exactly without the rest of the code... but this error happen when you try to access an element in a vector by using wrong indices.
In this case it seems you have a vector with only 2 columns... maybe 'Capacitance' or 'inductance' and temp exceeded 2.
Thank you both so much i'll try to work it out

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

답변 (1개)

Voss
Voss 2020년 11월 24일

0 개 추천

This means that the code is attempting to refer to an index of some variable, but the variable is not large enough in that dimension. In this case the dimension is the second dimension ("index in position 2") and the maximum index you can reference is 2 ("(must not exceed 2)").
So basically Capacitance and/or inductance has two columns, but the code is trying to access the third or higher column, which doesn't exist.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2020년 11월 24일

댓글:

2020년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by