问题描述
在MATLAB中,我运行一些需要一段时间运行的代码。我想暂停代码来检查一些变量值。有没有办法可以做到这一点,而不必从头开始重新运行代码?我不想终止程序;只需暂停它。您可以通过两种方式停止执行并给出命令提示符:
- 在您要停止的代码中放入
键盘
。 - 设置断点。
您可以使用 dbcont $ c $恢复并停止执行c>和
dbquit
。要转发,请使用 dbstep
。 dbstack
让你看到你在哪里。还有更多命令。这些帮助页面将为您提供其他建议。
正如Dennis Jaheruddin所指出的, In MATLAB, I'm running some code which takes a while to run. I'd like to pause the code to check on some variable values. Is there a way I can do this without having to re-run the code from the beginning? I don't want to terminate the program; just pause it. You can halt execution and give a command prompt in two ways of which I am aware: You can resume and stop execution with As Dennis Jaheruddin has pointed out, 这篇关于你可以暂停MATLAB吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! dbstop
有几个有用的功能值得尝试。特别是能够通过 dbstop if
语法来设置条件和全局(任何符合条件的线)断点。例如,如果错误,那么 dbstop将会在任何错误时中断调试命令提示符。他现在做的一个建议是把
dbstop if error
into startup.m
,以便这个行为当您启动MATLAB时将默认。您可能需要在 userpath
文件夹中创建此文件; edit(fullfile(regexp(userpath,'^ [^;] *','match','once'),'startup.m'))
> keyboard
in your code where you want to stop.dbcont
and dbquit
, respectively. To step forward, use dbstep
. dbstack
lets you see where you are. There are many more commands. The help page for any of these will give you other suggestions.dbstop
also has several useful features worth trying. In particular is the ability to set conditional and global (any line meeting a criterion) breakpoints via the dbstop if
syntax. For example, dbstop if error
will break to a debugging command prompt on any error. One suggestion he made, which I now do, is to put dbstop if error
into startup.m
so that this behavior will be default when you start MATLAB. You may need to create this file in a userpath
folder; edit(fullfile(regexp(userpath,'^[^;]*','match','once'),'startup.m'))
.