matlab怎么抛出错误,matlab – 如何在调用fprintf或disp时抛出错误?

dbstop in

当然你可以重载disp或fprintf,或者你可以告诉调试器使用dbstop停止这些功能.然后使用dbstack查看你的位置以及你是如何到达那里的.没有MATLAB代码就可以内置这些内容.它将在通话前停止:

>> dbstop in disp

Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>disp" is not a MATLAB code file.

Instead, the debugger will stop at the point right before "libmwbuiltins>disp" is called.

>> dbstop in fprintf

Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>fprintf" is not a MATLAB code file.

Instead, the debugger will stop at the point right before "libmwbuiltins>fprintf" is called.

看起来不错!

考虑以下带有嵌套函数fprintTest的测试函数testdbstop:

function testdbstop

x=1;

disp(x)

fprintTest(x)

function fprintTest(x)

fprintf('%d\n',x);

end

end

从命令行运行它:

>> testdbstop

3 disp(x)

K>> dbstack

> In testdbstop at 3

K>> dbcont

1

6 fprintf('%d\n',x);

K>> dbstack

> In testdbstop>fprintTest at 6

In testdbstop at 4

K>> dbcont

1

你有它 – 在testdbstop.m的第3行调用disp,在testdbstop> testdbstop的第4行调用的testdbstop> fprintTest中的testdbstop.m的第6行调用fprintf.

注意:完成后,使用dbclear删除虚拟断点(即db中的dbclear和fprintf中的dbclear).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值