How to use matlab debugger

4 Ansichten (letzte 30 Tage)
YI CHONG ONG
YI CHONG ONG am 11 Sep. 2020
Kommentiert: YI CHONG ONG am 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]);

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by