dbstop within a condition
11 次查看(过去 30 天)
显示 更早的评论
Looking to use dbstop if I get into an if statement, so that a break point will be added to next line. I'm presently doing this by the following:
if StoredTextSettings{end,8} < StoredTextSettings{end,7}
dbstop at 67
pause(0.001)
end
where the pause(0.001) is line 67. What I want to do is to have location set as a variable so that I can edit code without having to change the hard-coded line "at location". I want to have something like:
if StoredTextSettings{end,8} < StoredTextSettings{end,7}
PresentLine = MFileLineNr(); % Fex function to get present line number
dpstop at PresentLine + 2
pause(0.001)
end
This will enable the code to be modified before the hardcoded line number(s) and should I exit matlab and forget to enable my own break point (presently how I do things, or just let error on dbstop() then have to repeat the code run (having enabled pausing on errors), which is obviously terrible programming! I've tried:
dbstop if StoredTextSettings{end,8} < StoredTextSettings{end,7}
but this didn't work as I thought it would, and neither of the following get the desired result
dbstop in TestDBStop if StoredTextSettings{end,8} < StoredTextSettings{end,7}
dbstop in TestDBStop.m if StoredTextSettings{end,8} < StoredTextSettings{end,7}
Anyone any tips on how to implement what I want (encounter a condition, and then enable a break point in that condition when the line number may change)? Thanks in advance
0 个评论
采纳的回答
Sean de Wolski
2018-8-17
编辑:Sean de Wolski
2018-8-17
I think keyboard() does exactly what you want. It just stops at that line in debug mode.
But to find the number, I'd consider doing a contains() on the rows of a file after reading it in with fileread().
So
T = contains(string(fileread(mfilename)));
rownum = find(contains(T, '<Stop Here>'));
Now the row is:
pause(0.01) % <Stop Here>
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!