How to solve "Index exceeds the number of array elements (39)."
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
KALYAN ACHARJYA
am 10 Nov. 2019
Bearbeitet: KALYAN ACHARJYA
am 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!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Stress and Strain finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!