MATLAB: How to keep a MATLAB Project directory on the MATLAB path after closing the project

MATLAB

When I open a MATLAB Project, the contents of the project are automatically added to the MATLAB path. However, when I close this project, the project directory is removed from the MATLAB path. How can I make the project directory persist on the path after closing?

Best Answer

A project is designed to be transient - when it is opened, the MATLAB environment is configured for that project. When it is closed, every part of that environment is torn down again leaving you with a clean path.
On the other hand, toolboxes are designed to be permanent and provide support for this workflow - they persist on the MATLAB Path after installation. Consider using a Toolbox rather than a Project to support this workflow.
If you would like to permanently add the Project directory to the MATLAB path, you can do so using the following workaround:
% this command will add the Project directory to the MATLAB path for the current session of MATLAB
addpath('C:\Users\<username>\MATLAB\Projects\<projectName>)
% this command will save the Project directory to the MATLAB Path permanently
savepath
Related Question