Error : Index exceeds the number of array elements
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
David Fletcher
on 19 Apr 2021
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!