调试MATLAB:在某一行发生错误之前中断 [英] Debugging MATLAB: Break before an error at certain line

查看:266
本文介绍了调试MATLAB:在某一行发生错误之前中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的代码中找到一个错误。错误是在第三级的功能,最初工作完美,但不知何故在一个点停止(该函数在一个循环内被多次调用)。



错误说该变量是未定义的(它不会在开始时发生,但是超过150次)。我可以在句子之前写一些条件,以便在错误之前停止它吗?然后我可以知道为什么这个变量没有被定义。

解决方案

使用 dbstop if error dbstop 命令将在错误发生时将您带到停止的函数中的命令提示符。



您还可以在LINENO的FILESPEC中使用 dbstop如果EXPRESSION 语法。例如,如果您想要在该行出现错误之前不存在该变量,则说出 myFun.m 的行224:

  dbstop in myFun.m at 224 if〜exists('x','var')
/ pre>

然后它将停在 myFun.m 的第224行,如果 x 不是变量。


I'm trying to find an error in my code. The error is in a function of 3rd level that initially works perfectly, but somehow at one point stops (the function is called many times within a loop).

The error says the variable is undefined (it doesn't happen at the beginning, but after more than 150 times). Could I write some condition atop the sentence to stop it just before the error? Then I could know why this variable is not defined anymore.

解决方案

Use dbstop if error. That dbstop command will take you to command prompt in the stopped function when the error occurs.

You can also get tricky and use the dbstop in FILESPEC at LINENO if EXPRESSION syntax. For example, if you want to break if the variable doesn't exist right before the line that trips the error, say line 224 of myFun.m:

dbstop in myFun.m at 224 if ~exist('x','var')

Then it will stop at line 224 of myFun.m if x is not a variable.

这篇关于调试MATLAB:在某一行发生错误之前中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆