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

1 vue (au cours des 30 derniers jours)
Syifa Rizal
Syifa Rizal le 10 Nov 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 commentaire
Oren B
Oren B le 10 Nov 2019
i can't check your code cuse you have
missing parameter value: x0 , y0

Connectez-vous pour commenter.

Réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 10 Nov 2019
Modifié(e) : KALYAN ACHARJYA le 10 Nov 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!

Catégories

En savoir plus sur Stress and Strain dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by