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

1 回表示 (過去 30 日間)
Syifa Rizal
Syifa Rizal 2019 年 11 月 10 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 10 日
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 件のコメント
Oren B
Oren B 2019 年 11 月 10 日
i can't check your code cuse you have
missing parameter value: x0 , y0

サインインしてコメントする。

回答 (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 Center および File ExchangeStress and Strain についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by