index exceeds matrix dimension,Subscript indices must either be real positive integers or logicals
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tsering norbu
el 21 de Mzo. de 2019
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 comentarios
Andy
el 22 de Mzo. de 2019
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
el 22 de Mzo. de 2019
Editada: KALYAN ACHARJYA
el 22 de Mzo. de 2019
Please share complete code, so that we can see the issue?
Respuesta aceptada
KSSV
el 22 de Mzo. de 2019
Editada: KSSV
el 22 de Mzo. de 2019
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!