Nested While and For Loop
1 回表示 (過去 30 日間)
古いコメントを表示
Have the following code with an error stating "Array indices must be positive integers or logical values." Could someone point me in the direction of what this error means or why i'm getting it. It occurring in the second while and i'm assuming will happen again in the third
Eqn1 = @(x) 5*(1-erf(3*x));
Eqn2 = 0;
Eqn3 = @(x) 5*(1-erf(3*(x-30)));
X0 = 0;
X1 = 1;
X29 = 29;
X30 = 30;
Int1 = 10;
Int2 = 100;
Value1 = ((X1-X0)/Int1);
Value2 = ((X29-X1)/Int2);
AreaReq5 = 0;
while (X0 < X1)
AreaReq5 = AreaReq5+(Value1/2)*(Eqn1(X0)+Eqn1(X0+Value1));
X0 = X0+Value1;
while (X1 < X29)
AreaReq5 = AreaReq5+(Value2/2)*(Eqn2(X1)+Eqn2(X1+Value2));
X1 = X1+h5b;
end
while (X29 < X30)
AreaReq5 = AreaReq5+(Value1/2)*(Eqn3(X29)+Eqn3(X29+Value1));
XNow = X29+Value1;
end
end
0 件のコメント
採用された回答
その他の回答 (1 件)
Stephen23
2018 年 10 月 31 日
You define Eqn2 to be zero:
Eqn2 = 0;
and then inside the loop you try to access it using indexing:
Eqn2(X1+Value2)
When the error occurs the value of that index is:
>> X1+Value2
ans = 1.2800
Clearly this is not an integer.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!