【发布时间】:2016-08-06 12:25:26
【问题描述】:
出于调试目的,我想打印出 m 文件的名称和行号,以便在出现问题时显示类似
Error at 197th line of run.m
鉴于 Matlab 显示了这种类型的错误消息,必须有解决方案。
我该怎么做?
===========后续问题==============
谢谢!但我有一个后续问题。
我有 main.m,它是主 m 文件,而 main.m 调用 lower.m
我写了
info = dbstack()
和
try
error('Toto')
catch ME
ME.stack
end
到 main.m。然后matlab显示
info =
file: 'main.m'
name: 'main'
line: 15
ans =
file: 'C:\Users\account1\Google Drive\1AAA-RA\11HHJK(O…'
name: 'main'
line: 18
但是,当我将 dbstack 和 try-catch 的东西写到 lower.m 时,Matlab 不会显示任何确切的信息。
我运行了 main.m 和 main.m 称为较低级别的 m 文件,但它不显示任何信息。
info =
2x1 struct array with fields:
file
name
line
ans =
2x1 struct array with fields:
file
name
line
如何让它显示每个文件、名称、行信息?
理想情况下,Matlab 会同时显示 main.m 和 lower.m 的信息,如下所示:
file1: 'main.m'
name1: 'main'
line1: 15
file2: 'lower.m'
name2: 'lower'
line2: 6
这可能吗?
【问题讨论】:
-
是的,您在结构中有可用的信息:info = 2x1 struct 带有字段的数组:。尝试在命令窗口中输入
info(1)。另外,请阅读有关访问structure字段的信息...
标签: matlab