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

5 次查看(过去 30 天)
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 个评论
VINAYAK LUHA
VINAYAK LUHA 2024-1-30
Is it possible to add some sample fail cases, function code and the variable from function workspace which you want to save?

请先登录,再进行评论。

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2024-1-30
编辑:Fangjun Jiang 2024-1-30
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
MyFun
end
function MyFun
try
% do your routine
catch
% save your workspace
return
end

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by