MATLAB: How to save filepath for App after closing

MATLAB

I have a deployed application where users need to specify a file. The default for where the file browser launches is in the root and users have to navigate very far to get to the files they want which is fine. While the app is still open, the user can open another file but when the file explorer opens again it is not at the root but the directory where their last file was opened. This is good.
The issue arises when the app is closed, reopened, and a file is search, the user has to navigate to their files from the root again. Is there a way to save a file path that can be saved between sessions of using the app? 

Best Answer

You can refer to the function below which acts as a variation of 'uigetfile'. It makes a folder in the machine's temp directory and updates a MAT file on the most recently used path. 
 
function file = last_directory()
    cd(tempdir);
    folder_exists = exist('load_path_for_app', 'dir');
    if(~folder_exists)
        mkdir load_path_for_app;    
        [file, savedpath, filteridx] = uigetfile();
    else
        cd('load_path_for_app');
        load('savedpath.mat');
        [file, savedpath, filteridx] = uigetfile(savedpath);
    end
    cd(tempdir);
    cd('load_path_for_app');
    if(filteridx)
        save('savedpath.mat', 'savedpath');
        cd(savedpath);
    end
end