MATLAB: How to keep/use last used CURRENT DIR

cdcurrent foldermatlab environment

One decision has proposed by om_s (at russian matlab-forum):
% put this file in matlabroot\toolbox\local\startup.m
cd_path=strcat(prefdir,'\cwdhistory.m');cd_dir=importdata(cd_path);
cd_path=cd_dir{1};cd(cd_path);clear cd_path cd_dir;
But I don't believe that there is no decision by MATLAB IDE way (any radiobutton or…). The goal is: every MATLAB session begins with current folder that have used in last session.

Best Answer

I think in order to be consistent with the -r and -sd (Windows only) startup flags and environment variables on UNIX, it might be better to change userpath in finish.m. This way, if a startup path is specified, it does not get overwritten. I would simply add:
userpath(pwd)
to finish.m. This way also handles the case where the last directory is deleted after quitting MATLAB.