If you have a long running function that you just wrote and need to debug, type this in the Matlab command window:
dbstop if error
This will cause the debugger to kick in as soon as a Matlab error is thrown, so you can trace the variables in your function which are erased from memory as soon as the function is exited. To remove this behaviour, type:
dbclear if error