Filter löschen
Filter löschen

Save data when an error occurs inside a function.

18 Ansichten (letzte 30 Tage)
Hung Dao
Hung Dao am 2 Apr. 2021
Kommentiert: Stephen23 am 7 Apr. 2021
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
Hung Dao
Hung Dao am 7 Apr. 2021
Thanks Stephen.
Will it work if I run my code on a shared computational cluster?
Stephen23
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Steven Lord
Steven Lord am 2 Apr. 2021
Either set an error breakpoint before running the code or use a try / catch block. The error breakpoint will let you debug the code but will stop execution at the point of the error, which may not be what you want if you're running this code repeatedly and want to move on to the next iteration and come back later to determine what happened. The try / catch block will let you do whatever cleanup (saving the data, closing figures or files, etc.) you need to do before continuing on but won't let you debug the code from the point at which it failed.
  5 Kommentare
Steven Lord
Steven Lord am 7 Apr. 2021
Look at the contents of the stack property of the MException object named ME in the try / catch block.
Hung Dao
Hung Dao am 7 Apr. 2021
Thanks. I will try.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by