How to use matlab debugger

4 次查看(过去 30 天)
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.

类别

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