MATLAB: Dbstop within a condition

dbstopdbstop at locationpausing

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

Best Answer

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>