Error : Index exceeds the number of array elements
조회 수: 1 (최근 30일)
이전 댓글 표시
I am getting this error at line 25 for phi(i). How can i resolve this
t = 0.12;
Vinf = 1;
ang = 0;
n = 50;
c = 1;
j1 = 1:1:(n/2)+1;
dx = 2*c/n;
p0= 0.2969;
p1=-0.1260;
p2=-0.3516;
p3= 0.2843;
p4=-0.1015;
X = (j1-1)*dx;
Y1 = X .* (t/0.2) .* (p0*sqrt(X) + p1*X + p2*X.^2 + p3*X.^3 + p4*X.^4);
for i=1:n
phi(i)=-ang+atan2((Y1(i+1)-Y1(i)),(X(i+1)-X(i)));
beta(i)=phi(i)+pi/2;
mpX1(i)=(X(i+1)+X(i))/2;
mpY1(i)=(Y1(i+1)+Y1(i))/2;
S(i)=sqrt((Y1(i+1)-Y1(i))^2+(X(i+1)-X(i))^2);
end
댓글 수: 0
채택된 답변
David Fletcher
2021년 4월 19일
Y1 and X will be the same dimension as j1 - (n/2)+1 (26). Once your for loop counter hits 26 you will get an error since you are trying to index elements that do not exist. The highest value of i that your for loop can run to is n/2
댓글 수: 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!