Breakpoints in code. Something equivalent to the Stop command in interpreted Basic.
古いコメントを表示
I'm wanting to put permanent breakpoints in code. Something equivalent to the Stop command in interpreted Basic. As with the Editor's breakpoints, I want the cursor to be at the interruption point. And I want to continue with F5. Any ideas?
採用された回答
その他の回答 (1 件)
Walter Roberson
2017 年 3 月 6 日
編集済み: KSSV
2021 年 2 月 10 日
2 投票
8 件のコメント
John
2017 年 3 月 6 日
Walter Roberson
2017 年 3 月 6 日
The editor breakpoints are dbstop commands. If you click in the editor to set a breakpoint and use "dbstatus" you will see a dbstop is in effect; likewise if you dbstop and then open the file in the editor you will see the breakpoint graphic in the appropriate place.
To stop at the line after the current one, you can use
ST = dbstack; dbstop('in', ST.file, 'at', str2num(ST.line+1));
John
2017 年 3 月 7 日
Walter Roberson
2017 年 3 月 7 日
Ah, it should probably be
ST = dbstack; dbstop('in', ST(1).file, 'at', str2num(ST(1).line+1));
Walter Roberson
2017 年 3 月 7 日
function STOP
ST = dbstack;
if length(ST) < 2; return; end
dbstop('in', ST(2).file, 'at', str2num(ST(2).line+1));
end
Put that on your path, and then you should be able to insert calls to
STOP
Note: I have not tested to see what happens if the next line is not executable or is the end of a control structure.
Ali Komai
2020 年 11 月 24 日
Thanks Walter, very useful little function! You have there a little typo though. It should read num2str and not str2num.
John
2020 年 11 月 24 日
Ivan Nascimento
2021 年 7 月 8 日
編集済み: Ivan Nascimento
2021 年 7 月 8 日
Walter's STOP worked perfectly for me but only once I changed str2num to num2str, since dbstop receives a string as argument and ST(2).line is double. It works even when it is called before a comment or blank line (it stops in the next executable line, if it exists). Thank you, Walter!
EDIT. From dbstop help: To resume execution, use dbcont or dbstep. To exit from the debugger, use dbquit.
カテゴリ
ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!