Is it possible to set the startup directory to be the directory I was in when I ended the previous session of MATLAB?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 30 de Jul. de 2013
Editada: MathWorks Support Team
el 28 de Abr. de 2023
I would like to have MATLAB remember my last directory and use that as my startup directory in the subsequent session.
Respuesta aceptada
MathWorks Support Team
el 27 de Abr. de 2023
Editada: MathWorks Support Team
el 28 de Abr. de 2023
The ability to preserve the directory between sessions is not available in MATLAB.
To work around this issue, you may use finish.m to have MATLAB use the last directory and use that upon starting a new session. The finish.m file would store the pathname of the last directory into your user path.
The finish.m file would include the lines:
p = pwd;
userpath(p);
savepath;
Note that the command FINISH automatically executes before leaving MATLAB if the file finish.m exists on the path. More information on this functionality can be found in the documentation by typing
doc finish
Alternatively, it is possible to use startup.m and finish.m files in order to have MATLAB remember the last directory and use that upon starting a new session. The finish.m file would store the pathname of the last directory into a variable, and the startup.m file would load this variable and use its contents to determine what to change the current directory to.
The startup.m file would include the lines
if (exist([matlabroot filesep 'work' filesep 'last_dir.mat']) == 2)
load ([matlabroot filesep 'work' filesep 'last_dir'])
cd(last_dir);
end
whereas the finish.m file would include the lines
last_dir = pwd;
save([matlabroot filesep 'work' filesep 'last_dir'],'last_dir');
Note that the command STARTUP automatically executes when starting MATLAB if the file startup.m exists, and the command FINISH automatically executes before leaving MATLAB if the file finish.m exists. More information on this functionality can be found in the documentation by typing
doc startup
doc finish
0 comentarios
Más respuestas (1)
Greg
el 15 de Feb. de 2018
Editada: MathWorks Support Team
el 26 de Abr. de 2023
This is now a first-class-citizen preference option. This was introduced to general preferences in R2014b.
0 comentarios
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!