Pause on error, run calculation in that workspace, and resume the script

5 visualizzazioni (ultimi 30 giorni)
I have 88 "Cases" that I know will throw an error when running a function. I would like to automate saving a value from this functions workspace, kill that function excecution, and then continuing a for loop to the next case. I've tried try and catch but it seems to still skip past the desired workspace. There is a manual workaround using pause on error when running and setting a break point on the error command, but I was hoping to automate this process.
  1 Commento
VINAYAK LUHA il 30 Gen 2024
Is it possible to add some sample fail cases, function code and the variable from function workspace which you want to save?

Accedi per commentare.

Risposte (1)

Fangjun Jiang
Fangjun Jiang il 30 Gen 2024
Modificato: Fangjun Jiang il 30 Gen 2024
What do you mean by "skip past the desired workspace"? I think it should work using try-catch.
If you don't have access to the source code/inside contents of the function, then I think you are out of luck. The try-catch inside the for-loop but outside of the function can only catch when the error occured at the fucntion, by then, the function workspace is destroyed.
So, it is better to put try-catch inside the function, if it is possible.
for k=1:100
function MyFun
% do your routine
% save your workspace


Scopri di più su Programming in Help Center e File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by