for loop execution error

1 回表示 (過去 30 日間)
MUKESH KUMAR
MUKESH KUMAR 2019 年 9 月 6 日
コメント済み: Sebastian Körner 2019 年 9 月 6 日
i had a for loop like this
for j=1:100
for i=1:48
F{j,1}(i,1)= some equations;
end
end
this is running well when j (1:100)>i(1:48) and not running for j<i values like if
for j=1:30
for i=1:48
F{j,1}(i,1)= some equations;
end
end
then its F cell having only 30 values for i=30th values . but I need 48 values when j=1:30 means F cell size should be {30,1} and each cell having (1*48) array.
and in another for loop,
for t=1:100
G(t)=trapz(X(t),Y(t));
end
if at G(55) its values can not calculated due to X(55) or Y(55) have no values/data sufficient for its operation then how can I execute this for loop without the error because I need the array untill the error come or not come G(55) is needful for me before the error and want to continue the program .

採用された回答

Sebastian Körner
Sebastian Körner 2019 年 9 月 6 日
For your second problem try:
for t=1:100
try
G(t)=trapz(X(t),Y(t));
catch
continue;
end
end
when the error occures at t=55 , you jump to the catch part and your loop continues with the next iterration
  2 件のコメント
MUKESH KUMAR
MUKESH KUMAR 2019 年 9 月 6 日
thanks for your helps it working well but then after execution the G vector values from 56 to 100 is zero and size of G is (100,1) but i want it till G(55,1) only
Sebastian Körner
Sebastian Körner 2019 年 9 月 6 日
in this case simply replace the continue with break
for t=1:100
try
G(t)=trapz(X(t),Y(t));
catch
break;
end
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by