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)
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

Réponse acceptée

Cris LaPierre
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)
Index exceeds the number of array elements (2).

Plus de réponses (0)

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!

Translated by