필터 지우기
필터 지우기

dbstop within a condition

조회 수: 4 (최근 30일)
Pete
Pete 2018년 8월 17일
댓글: Pete 2018년 8월 17일
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

채택된 답변

Sean de Wolski
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>
  댓글 수: 1
Pete
Pete 2018년 8월 17일
Thanks Sean, exactly what I wanted! For those who are looking at something similar, use the following in the code:
if StoredTextSettings{end,8} < StoredTextSettings{end,7}
keyboard
end
This then opens up a DB point and allows you to continue as before.
Amazingly simple!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by