3.0

3.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 1.37 KB File ID: #19239

Restore previous working directory on MATLAB Startup

by Vihang Patil

 

17 Mar 2008 (Updated 18 Mar 2008)

This simple program will restore the last working directory on resuming MATLAB

| Watch this File

File Information
Description

This simple program will remember your last working directory and will prompt you on resuming MATLAB, whether the user wants to start in the last working directory or not
Just copy the contents of the zip file in the Matlabroot work directory
ex: c:\Matlab\R2006b\work and make sure that its on the path.
i.e type path on MATLAB command prompt and see if the above directory exists in the path. If the "work" directory does not exist on your path, then use the "pathtool" function to add the work directory manually.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
06 Jan 2009 Andreas Köhler

I made the following modification to finish.m such that my startup.m - which already contains important data - is not overwritten:

%%%%%%% finish.m %%%%%%
str = pwd;%store present working directory in the variable str

% figure out where to put restorewd script
pathstr=userpath;
if(isempty(pathstr))
  pathstr=[matlabroot filesep 'work'];
else
  pathstr=pathstr(1:find(pathstr==pathsep)-1);
end

fid = fopen(fullfile(pathstr,'restorewd.m'),'wt');%open file for writing
fprintf(fid,'answer = questdlg(''Do you want to continue working in the previous working directory'',''Restore Last Working Directory'',''Yes'',''No'',''Default'');\n');%write this and the following 3 lines into restorewd.m
fprintf(fid,'cd(''%s'');\n',str);
fprintf(fid,'end');
fclose(fid);%close file
%fprintf(fid,'end');
fclose(fid);%close file

Now, create or append to your existing startup.m:

if exist('restorewd')==2
  restorewd
end

Please login to add a comment or rating.
Updates
18 Mar 2008

1.Typo Error removed
2. Updated the Description part

Tag Activity for this File
Tag Applied By Date/Time
path Vihang Patil 22 Oct 2008 09:54:00
directories Vihang Patil 22 Oct 2008 09:54:00
files Vihang Patil 22 Oct 2008 09:54:00
previous working directory Vihang Patil 22 Oct 2008 09:54:00
restore Vihang Patil 22 Oct 2008 09:54:00
resume last working directory Vihang Patil 22 Oct 2008 09:54:00

Contact us at files@mathworks.com