How to use matlab debugger

2 views (last 30 days)
YI CHONG ONG
YI CHONG ONG on 11 Sep 2020
Commented: YI CHONG ONG on 23 Sep 2020
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]);

Accepted Answer

Adam Danz
Adam Danz on 11 Sep 2020
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 Comment
YI CHONG ONG
YI CHONG ONG on 23 Sep 2020
I realised the error. I was calling factorial on a very large number. Thank you for your help !

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 11 Sep 2020
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 Comment
YI CHONG ONG
YI CHONG ONG on 23 Sep 2020
Thank you for your help ! I managed to solve it.

Sign in to comment.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!