Display the error containing line in .m file

5 vues (au cours des 30 derniers jours)
Horia
Horia le 2 Août 2011
Is there a method to display the error containing line in .m file, when the execution stops?
  1 commentaire
Oleg Komarov
Oleg Komarov le 2 Août 2011
Your question sounds like:
How to pinpoint the line that errors in a "highlight some lines + F9"?

Connectez-vous pour commenter.

Réponses (3)

Jan
Jan le 2 Août 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 commentaires
Oleg Komarov
Oleg Komarov le 2 Août 2011
Anyways: 'dbstop if all error' works nevertheles on 2011a
Horia
Horia le 3 Août 2011
But no longer appearing in "Help".

Connectez-vous pour commenter.


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

Connectez-vous pour commenter.


Paulo Silva
Paulo Silva le 2 Août 2011
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 commentaire
Oleg Komarov
Oleg Komarov le 2 Août 2011
I get an empty stack if in a new .m file:
s = s(1)
l = lasterror

Connectez-vous pour commenter.

Catégories

En savoir plus sur Debugging and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by