When MATLAB starts, it automatically executes startup.m if the m file exists; and it runs a script finish.m when quiting. Therefore, we creat/edit these two files to make sure MATLAB starts in the last working directory.
************************************************
The content of startup.m:
if ispref('StartupDirectory','LastWorkingDirectory') lwd = getpref('StartupDirectory','LastWorkingDirectory'); try cd(lwd) catch disp('Sorry, but I could not go to your last working directory:') disp(lwd) end end
***********************************************************
finish.m:
setpref('StartupDirectory','LastWorkingDirectory',pwd)
*************************************************************
Reference: http://www.mathworks.com/matlabcentral/files/5793/StartupInLastDirectoryDirections.html