Display the error containing line in .m file

7 次查看(过去 30 天)
Is there a method to display the error containing line in .m file, when the execution stops?
  1 个评论
Oleg Komarov
Oleg Komarov 2011-8-2
Your question sounds like:
How to pinpoint the line that errors in a "highlight some lines + F9"?

请先登录,再进行评论。

回答(3 个)

Jan
Jan 2011-8-2
Perhaps you are looking for:
dbstop if error
or if you want to catch error inside TRY-CATCH also:
dbstop if all error
[EDITED]: In modern Matlab versions this is documented:
dbstop if caught error
Then the failing line is highlighted in the editor automatically.
  8 个评论
Oleg Komarov
Oleg Komarov 2011-8-2
Anyways: 'dbstop if all error' works nevertheles on 2011a

请先登录,再进行评论。


Fangjun Jiang
Fangjun Jiang 2011-8-2
It is usually indicated in the error message.
Also, help dbstack.
  5 个评论
Jan
Jan 2011-8-3
Under which circumstances does it (MATLAB?) show "error at" without a line number? Usually a line number is following.
Horia
Horia 2011-8-3
The line number in the function or library used by Matlab, but not the one in the .m file.

请先登录,再进行评论。


Paulo Silva
Paulo Silva 2011-8-2
After you get the error, execute this
l=lasterror;
fprintf('The last error was on line %d of the file called %s \n',...
l.stack.line,l.stack.name)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by