当我调试很长的数字代码时,我常常想看到函数变量值,如果发生了什么,或者在特定的迭代中.一般来说我做:
function banana(platano)
% long stuff here
for ii=1:123456789
% tons of maths
if ii==45612
stophere=1; % I put a break point in this line of code
end
end
Run Code Online (Sandbox Code Playgroud)
但是,这需要我在函数中编写代码进行调试,看起来并不好看.有更聪明的方法吗?
And*_*uri 14
其中一种方法是使用条件断点.您可以通过右键单击行号并选择"Set conditional Breakpoints..."选项来添加它们.
例:
如本答案的评论中所述,如果您想使用命令行进行设置,则可以使用
dbstop in filename at linenumber if condition
Run Code Online (Sandbox Code Playgroud)
举个例子:
dbstop in banana at 6 if ii==454345433
Run Code Online (Sandbox Code Playgroud)
请注意,该at linenumber和if condition是可选的.
如果出现错误,调试器的另一个有用工具就是打破程序,使用dbstop if error,如本问答中所示.
感谢@ Dev-il向我展示了这个!