Pause when there is an output

5 ビュー (過去 30 日間)
Iven Yi
Iven Yi 2020 年 2 月 4 日
コメント済み: Iven Yi 2020 年 2 月 4 日
Hi everyone,
I left some "warning codes ('fprintf ...')" in my script that give warnings about something. The problem is that I have too many scripts and I cannot easily figure out where the warning outputs come from. Is there any way to pause the program every time when there is an output or 'fprintf' is called? I do not want to write 'pause' in my program because most of the time I do not need it.
Thanks.

採用された回答

Guillaume
Guillaume 2020 年 2 月 4 日
編集済み: Guillaume 2020 年 2 月 4 日
1) Create your own fprintf function in a folder on the path (e.g. local folder) with code similar to:
function nbytes = fprintf(varargin)
nbytes = builtin('fprintf', varargin{:}); %call built-in fprintf
keyboard; %or pause. keyboard is probably more useful
end
2) run your code and do whatever it is you want to do when it breaks into the debugger in your custom fprintf function
3) when done, don't forget to get rid of the custom fprintf
4)in future, make sure that your debugging message include the name of the script/function that emits the message. Better than fprintf use warning which automatically displays that information.
  1 件のコメント
Iven Yi
Iven Yi 2020 年 2 月 4 日
Thanks for the solution and also the advice. Then I find I can use 'step out' in the dubug panel to jump to the function where it is called. Great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by