在任何运行时错误后在 Matlab 中指定回调 [英] Specifying a callback in Matlab after any runtime error
问题描述
有没有办法指定在 Matlab 中发生错误时要运行的代码?谷歌搜索我遇到了 RunTimeErrorFcn 和 daqcallback,但我相信这些是特定于数据采集工具箱的.当我被错误绊倒时,我想要一些东西,例如访问未分配的变量.(我使用一个名为 PsychToolbox 的库来接管 GPU,因此我希望能够在返回命令提示符之前清除其屏幕.)
Is there a way to specify code to be run whenever an error occurs in Matlab? Googling I came across RunTimeErrorFcn and daqcallback, but I believe these are specific to the Data Acquisition Toolbox. I want something for when I just trip over a bug, like an access to an unassigned variable. (I use a library called PsychToolbox that takes over the GPU, so I want to be able to clear its screen before returning to the command prompt.)
推荐答案
一个技巧是使用 错误断点 发出以下命令:
One trick is to use Error Breakpoints by issuing the command:
dbstop if error
启用后,会导致 MATLAB 在出现错误时进入调试模式.您可以从主工具栏上的 Debug
菜单访问相同的功能.
which when enabled, causes MATLAB to enter debug mode at the point of error. You can access the same functionality from the Debug
menu on the main toolbar.
这篇关于在任何运行时错误后在 Matlab 中指定回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!