Pause on error, run calculation in that workspace, and resume the script
6 次查看(过去 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
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!