I am getting an error Index exceeds the number of array elements in the following code. Kindly help me out with this problem.
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cris LaPierre
2021년 9월 20일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!