Save data when an error occurs inside a function.
Ältere Kommentare anzeigen
Hi,
I have an algorithm (called algorithm A) that takes hours to run. Algorithm A is written in a script file 'Algorithm_A.m'.
I will run alogirthm A in various cases, to make it easy for me to organize my code, I want to rewrite the script file 'Algorithm_A.m' as a function.
The thing I am concerned is that if I rewrite A into a function, will be it possible to debug the code if some error occurs inside this function?
A takes hours to run so it is important for me to check the data at the time where the error occurs.
Is it possible?
If it is, then could you tell me how to do it? How to save the data at the time where an error occurs?
Thanks !
3 Kommentare
Stephen23
am 7 Apr. 2021
The most useful debugging command is
dbstop if error
With this you do not need to set any breakpoints or even know where an error might occur. Just run that command, then run your code: it will stop on the line where any error occurs, and you have immediate access to all of the variables in the function workspace.
Hung Dao
am 7 Apr. 2021
Stephen23
am 7 Apr. 2021
"Will it work if I run my code on a shared computational cluster? "
I do not know. If it does not work, then probably the try-catch solution is your best choice.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Exception Handling finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!