Error : Index exceeds the number of array elements

1 vue (au cours des 30 derniers jours)
Garrett
Garrett le 19 Avr 2021
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

Réponse acceptée

David Fletcher
David Fletcher le 19 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by