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

1 次查看(过去 30 天)
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 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-11-10
编辑:KALYAN ACHARJYA 2019-11-10
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!

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by