I am getting an error Index exceeds the number of array elements in the following code. Kindly help me out with this problem.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nandini K K
le 20 Sep 2021
Réponse apportée : Cris LaPierre
le 20 Sep 2021
for i=2:n1
V(i)=(2*((v(i))^2)*(v(i+1))^2)-((2*(v(i+1))^2)*((p(i+1)*r(i))+(q(i+1)*x(i))))-(abs(zb)^2)*((p(i+1)^2)+(q(i+1)^2));
Vbase=V(i);
end
for i=2:n1
V(i)=(2*((v(i))^2)*(v(i+1))^2)-((2*(v(i+1))^2)*((P1(i+1)*r(i))+(q(i+1)*x(i))))-(abs(r(i)+x(i))^2)*((P1(i+1)^2)+(q(i+1)^2));
Vload=V(i);
end
0 commentaires
Réponse acceptée
Cris LaPierre
le 20 Sep 2021
We don't have enough information to tell you which variable is causing the problem. However, one of your variables has less than i values, so when you try to index into it using i, your index exceeds the size of the variable, resulting in the error message you are seeing.
% consider a variable with 2 values
a=[1 2];
% Try to index the 3rd value
a(3)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!