Thanks for this great contribution! I was looking for this functionality, and it works great!
@Eric I got around the error problem in finish.m by placing the history_preserved command in a try cath block. So finish.m will look like:
setpref('StartupDirectory','LastWorkingDirectory',pwd)
try
preserve_history;
catch EM
h=msgbox(EM.message,sprintf('Error: %s',EM.identifier),'error');
uiwait(h);
return
end
Now it won't 'hang' your matlab but just display an error dialog before closing.