Display the error containing line in .m file

조회 수: 6 (최근 30일)
Horia
Horia 2011년 8월 2일
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
Horia
Horia 2011년 8월 3일
But no longer appearing in "Help".

댓글을 달려면 로그인하십시오.


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)
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 8월 2일
I get an empty stack if in a new .m file:
s = s(1)
l = lasterror

댓글을 달려면 로그인하십시오.

카테고리

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