index exceeds matrix dimension,Subscript indices must either be real positive integers or logicals

조회 수: 1 (최근 30일)
I am a total noob in matlab and i am trying to write a code for water hammer simulation in a series pipe system, and the error i am getting is index exceeds matrix dimension, apparently for this line of code v1(1,t+dt1)=((((-a1)^2)*v1(2,t+dt1))/(h1(2,t+dt1)-h1(1,t+dt1))*g-a1^2); and also i am getting the error of Subscript indices must either be real positive integers or logicals, for the code h1(1,t+dt1)=Zu; this are both inlet boundary conditions. Zu has been defined earlier with a value of 40.
would be grateful if anyone can guide me through this or point towards something that can help me.
  댓글 수: 2
Andy
Andy 2019년 3월 22일
With only this line of code to examine, all that I can say is that it looks like t or dt1 are combining to produce an invalid number. Without seeing the rest of the code it is impossible to say how. If I get this sort of error I normally insert a statement disp(t) or leave the ; off the end of the line that sets the variable causing it to show in the command window. That usually points me in the right direction for further investigation.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 3월 22일
편집: KALYAN ACHARJYA 2019년 3월 22일
Please share complete code, so that we can see the issue?

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

채택된 답변

KSSV
KSSV 2019년 3월 22일
편집: KSSV 2019년 3월 22일
v1(1,t+dt1)=((((-a1)^2)*v1(2,t+dt1))/(h1(2,t+dt1)-h1(1,t+dt1))*g-a1^2)
In the above I could say that dt1 is a fraction...and you are tryigng to index arrays with fractions/ negatives. Note that MATLAB accepts only posittive integers and logicals as index.
A = rand(10) ;
A(1) % allowed, no error
A(10) % allowed, no error
A(1,2) % allowed, no error
A(-10) % error, index cannot be negative
A(0) % error, not allowed index cannot be zero unless it is logical.
A(1.25) % not allowed
You need to re think on your code.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by