How to solve "Index exceeds the number of array elements (39)."

1 visualización (últimos 30 días)
Syifa Rizal
Syifa Rizal el 10 de Nov. de 2019
Editada: KALYAN ACHARJYA el 10 de Nov. de 2019
When i run this code, it states:
Index exceeds the number of array elements (39).
Error in Structure2 (line 218)
z0Le(i) = z0LtW(i-1);
How can i fix this?
N=79
%% Stress Analysis
% Wing Stress Analysis
r = mod(N,2); %N is number of coordinate point airfoil
if r == 0
n = N/2;
else
n = (N+1)/2;
end
x0UW = x0(1:n,1);
z0UW = y0(1:n,1);
x0LtW = x0(n+1:N,1);
z0LtW = y0(n+1:N,1);
for i = 1:n+1
if i == 1
z0Le(i) = 0;
x0Le(i) = 0;
else
z0Le(i) = z0LtW(i-1);
x0Le(i) = x0LtW(i-1);
end
end
  1 comentario
Oren B
Oren B el 10 de Nov. de 2019
i can't check your code cuse you have
missing parameter value: x0 , y0

Iniciar sesión para comentar.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 10 de Nov. de 2019
Editada: KALYAN ACHARJYA el 10 de Nov. de 2019
The problem is here
z0Le(i) = z0LtW(i-1);
x0Le(i) = x0LtW(i-1);
When the loop iterate for first i=1, then, in the else statements,
z0LtW(i-1) becomes z0LtW(1-1)>> z0LtW(0);
MATLAB doesnot have zero indexing concept, as other programming allows (like python) either you have start the iteration from i=2 to.. or change the statements, so that it avoid (0) indexing in all statements.
For example:
x(1)>>Allow
x(2)>>Allow
x(100)>>Allow
x(-2)>>Not Allow
x(0)>>Not Allow
x( )
% ^Must be always real positive number
Hope you get the sufficients hints to solve the issue
Good Luck!

Categorías

Más información sobre Stress and Strain en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by