I have a Matlab script consisting of several cells that all can be executed independently (i.e. I may need to execute one cell in order to execute another, but until I clear the workspace, I will not be able to execute the second cell again without execution first). The code in these cells sometimes fails (of course), and if they are executed, I want to run a specific command.
Since the code spans several independent cells, I cannot use the try / catch block to accomplish this - unless I put one try / catch block in each cell, which I don't want. Each cell is quite short (a few lines with function calls, basically), so introducing a try / catch block in each cell is likely to double the length of the script.
In particular, I want to open the log file ( diary filename.log
) in the first cell, which automatically closes ( diary off
) after an error (and logs) from any cell. This option must be enabled at least until the log file is closed again and must be installed programmatically (I want to install it in the same cell, I open the log file).
How to do it?
source
share