Can we stop at particular number of iteration?
7 ビュー (過去 30 日間)
古いコメントを表示
I have a loop. The number of iteration is very big. Usually it produce error at iteration >500. can I run the loop and stop a few step before error? If I use debug, I need to run almost 500 iteration manually and it is tiring .
Best regard
Ali
3 件のコメント
採用された回答
Jan
2012 年 11 月 16 日
編集済み: Jan
2012 年 11 月 16 日
Solution 1:
dbstop if error
Then Matlab stops, when an error occurs.
Solution 2:
for k = 1:5e5
if k == 500
disp('dummy line'); % <- set a breakpoint in this line
end
... your code
end
Instead of a breakpoint, the "keyboard" command would be sufficient also.
Of course the debugger has more powerful options, but this simple methods work in other programming languages also and are easy to remember.
その他の回答 (1 件)
Lakshminarayana Reddy Tamatam
2018 年 11 月 20 日
Use 'keyboard' command to debug.
if i = 500
keyboard
end
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!