gpt4 book ai didi

MATLAB调试: smarter way to stop the code with an specific condition?

转载 作者:太空宇宙 更新时间:2023-11-03 19:14:55 27 4
gpt4 key购买 nike

当我调试较长的数字代码时,我通常希望在发生某些事情时或在特定迭代中查看函数变量值。通常我会这样做:

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

但是,这需要我在函数中编写代码进行调试,看起来不太好。有更聪明的方法吗?

最佳答案

其中一种方法是使用 Conditional Breakpoints .您可以通过右键单击行号并选择 “Set conditional Breakpoints...” 选项来添加它们。

例子:

enter image description here

正如这个答案的评论中所描述的,如果你想用你可以使用的命令行来设置它

dbstop in filename at linenumber if condition 

举个例子:

dbstop in banana at 6 if ii==454345433

请注意,at linenumberif condition 是可选的。

更多内容

调试器的另一个有用工具是在出现错误时中断程序,使用dbstop if error,如图in this Q&A .

感谢@Dev-il给我看这个!

关于MATLAB调试: smarter way to stop the code with an specific condition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34027454/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com