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!