Stuart’s MATLAB Videos

Watch and Learn

Setting Initial MATLAB Working Folder to Last Folder Used 5

Posted by Stuart McGarrity,

In release 2014b there is a new preference that lets you set MATLAB’s initial working folder to be the last folder used in the previous MATLAB session. Here I show when it can be useful and when you can’t use it.

5 CommentsOldest to Newest

Jon replied on : 1 of 5
This is great i am surprised it took this long to add this feature. Also the videos are no longer flash, geat job Stuart!!
Moiz replied on : 3 of 5
Hi Stuart, This is a useful feature. In general I was wondering if its possible to remember the last selected folder with uigetfile or uigetdir. I saw a modified uigetdir2 in a file exchange submission that does this, but is there an alternative way ?
Stuart McGarrity replied on : 4 of 5
There isn't a way built into MATLAB. I see uigetfile2 uses a MAT file to store the last folder. I think a better way is to create a preference group (e.g. 'uigetfile') and preference name (e.g. 'lastFolder') and just use uigetfile. Try this: if ispref('uigetfile','lastFolder') lastFolder=getpref('uigetfile','lastFolder'); [fileName,pathName] =uigetfile({'*.*','All Files' },'Choose a File',lastFolder); else [fileName,pathName] =uigetfile({'*.*','All Files' },'Choose a File'); end setpref('uigetfile','lastFolder',pathName);