How to use matlab debugger

조회 수: 4 (최근 30일)
YI CHONG ONG
YI CHONG ONG 2020년 9월 11일
댓글: YI CHONG ONG 2020년 9월 23일
I am running a matlab program on the command line without any GUI. I inserted the line "dbstop if naninf" just before the function. (within this function contains many other functions as well) that returned a value NaN. However, when the debugger stopped at the line which gives the error, the line it stops at shows that it stops at factorial.m file. I do not have this file or the function "cumprod" in any of my functions. How do I find the execution line in my files that gives me the actual error ? There is a factorial function in my actual file. Is that where the error comes from ?
NaN/Inf breakpoint hit for factorial.m on line 33.
33 Fa = cumprod([1 1 2:m]);

채택된 답변

Adam Danz
Adam Danz 2020년 9월 11일
Matlab's factorial() function is being called somewhere when your code is executed.
cumprod is a variable within factorial.m.
When the break happens, go to the command window and enter dbstack. This will display the caller stack that shows which functions/scripts were called that lead to factorial.m.
  댓글 수: 1
YI CHONG ONG
YI CHONG ONG 2020년 9월 23일
I realised the error. I was calling factorial on a very large number. Thank you for your help !

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 9월 11일
Show us the whole stack at which MATLAB is stopped.
dbstack
You're stopped inside the factorial function that is included with MATLAB. Either your code is calling factorial or it's calling something that eventually causes it to be called.
If you want to skip past the factorial call use dbcont. MATLAB will continue executing until the next time that error breakpoint's condition is satisfied.
  댓글 수: 1
YI CHONG ONG
YI CHONG ONG 2020년 9월 23일
Thank you for your help ! I managed to solve it.

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

카테고리

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