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 Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by