MATLAB Answers


Display the error containing line in .m file

Horia 님이 질문을 제출함. 2 Aug 2011
Is there a method to display the error containing line in .m file, when the execution stops?

  댓글 수: 1

Your question sounds like:
How to pinpoint the line that errors in a "highlight some lines + F9"?

로그인 to comment.

답변 수: 3

Answer by Jan
on 2 Aug 2011

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

표시 이전 댓글 수: 5
dbstop in file
dbstop in file at location
dbstop in file if expression
dbstop in file at location if expression
dbstop if condition
Mathworks seems to love play "hide and seek", until they come with another release...
Anyways: 'dbstop if all error' works nevertheles on 2011a
But no longer appearing in "Help".

로그인 to comment.

Answer by Fangjun Jiang
on 2 Aug 2011

It is usually indicated in the error message.
Also, help dbstack.

  댓글 수: 5

표시 이전 댓글 수: 2
The standard error message traceback shows not only any chain of library calls, but also the line in the user .m file
on 3 Aug 2011
Under which circumstances does it (MATLAB?) show "error at" without a line number? Usually a line number is following.
The line number in the function or library used by Matlab, but not the one in the .m file.

로그인 to comment.

Answer by Paulo Silva
on 2 Aug 2011

After you get the error, execute this
fprintf('The last error was on line %d of the file called %s \n',...

  댓글 수: 1

I get an empty stack if in a new .m file:
s = s(1)
l = lasterror

로그인 to comment.

Translated by