MATLAB: How to get an ouput of a function in a try block

try block

Hello !
I have the following function:
h = MyFunction(arg1,arg2);
Unfortunately it doesn't run because if an error occurs in MyFunction, ouput h isn't in the workspace of the main function. Yet, h is set in MyFunction before the error occurs.
How can I close a window opened by MyFunction, with the handle h, if an error occurs in MyFunction ?
Thank you for your help.

Best Answer

  • Add a try block to MyFunction!
    Well that's the easiest way and it's pretty safe. You could also use assignin if you really just want h.