Error : Index exceeds the number of array elements

3 visualizaciones (últimos 30 días)
Garrett
Garrett el 19 de Abr. de 2021
Respondida: David Fletcher el 19 de Abr. de 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

Respuesta aceptada

David Fletcher
David Fletcher el 19 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by