I am getting an error Index exceeds the number of array elements in the following code. Kindly help me out with this problem.
1 view (last 30 days)
Show older comments
Nandini K K
on 20 Sep 2021
Answered: Cris LaPierre
on 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 Comments
Accepted Answer
Cris LaPierre
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!