Matlab Path File Management

13 views (last 30 days)
Shiryaev
Shiryaev on 14 Jun 2015
Commented: Shiryaev on 17 Jun 2015
I have been a Matlab user since 1998. Management of the "matlab path" has changed and improved over the years, but it is still not quite what I want.
I presently use Matlab R2015a on four machines simultaneously for my doctoral research. All of my research related m-files and mat-files are in a single cloud folder called "work" neatly organized into subfolders. The folder "work" and all of its subfolders are on the "matlab path" on all four installations of Matlab R2015a.
This scenario works very well for simultaneous changes to any m-files or mat-files within the cloud folder "work" or any of its subfolders. However, changes to subfolder names, the deletion of subfolders, and the creation of new subfolders is less than ideal. All four "matlab paths" need to be updated for this. The result is that I am discouraged from making any subfolder changes, and certain subfolders get overused until they absolutely have to be changed on all four machines. Note that this would still be inconvenient even if I were only using one machine.
What I would like to see in a future release of Matlab, is a "matlab path" management system whereby there is a default option to set a folder, say for example "work", such that all of its subfolders are automatically on the "matlab path" any time that such subfolders reside in the folder "work". In particular I want to see this remain the case when subfolders of the folder "work" are changed.
I am aware that this option could take more Matlab resources to maintain than the current "matlab path" management setup. For this reason it could be made into a user defined option, and I do actually suggest that it should be the default.
What are the reasons that an automatic "matlab path" folder management system such as this is currently not a part of Matlab?
  4 Comments
per isakson
per isakson on 16 Jun 2015
Edited: per isakson on 16 Jun 2015
Thank you, now I understand better, but not fully.
I agree that's a bit awkward to rename a folders, which is on the Matlab path. Firstly, I cannot rename it in the Matlab Current Folder Window. I'm making the tests on R2013a.
I have to remove it from the path, rename it, add it to the path and finally save the path. With Windows Explorer I can rename it, but that confuses Matlab.
Deleting a folder on the path and then start Matlab results in 1) a warning and 2) Matlab automatically removes the folder from the current path.
However, Matlab doesn't save the current path and at next start the same warning is issued again. It seems, one has to save the path interactively.
"four machines all need to be updated individually by hand" &nbsp This is the issue I don't fully understand. If all machines start in the same folder, i.e. use the same "startup-folder", they will all at start automatically load the same path stored in h:\m\startup\pathdef.m (on my system). There should be no need to do that "individually by hand".
Shiryaev
Shiryaev on 16 Jun 2015
Glad that you now understand that it is changing folders on the matlab path that creates issues. What I have been doing for years now to address this problem is to wait until I have a reasonable number of folder changes to make, then do the following: 1) Make folder changes to primary matlab folder "work" in Windows explorer. 2) Set matlab path to default and save. 3) Reset matlab path to include all subfolders of folder "work" and save. This is what I mean by "setting the path manually". Because folder "work" is the only matlab folder in my cloud, the path on all four machines needs to be reset in the same way. I suppose that I could store my matlab startup folder on my could, but I don't want to do that. I would rather let matlab manage my startup folder.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 16 Jun 2015
Why don't you just use genpath to put your work folder and all it's subfolders on the path? Put this line in your startup.m file and then it doesn't matter what you do to folders in your work folder - you can rename them, delete them, add new ones, whatever - it will update it every time you launch MATLAB.
addpath(genpath('D:/Matlab/work'));
savepath;
  1 Comment
Shiryaev
Shiryaev on 17 Jun 2015
This appears to be precisely the command line version of what I do manually in the matlab gui. Because it is written in command line it can be put in the startup.m file, and run automatically. This is the answer that I was looking for. It is accepted.

Sign in to comment.

More Answers (1)

Jan
Jan on 14 Jun 2015
Edited: Jan on 14 Jun 2015
I'm working with different projects in a lab with 12 computers and several colleagues, which are running different projects also. Some folders containing basic tools are shared between the projects, others are distinct.
Therefore we are using a dedicated tool to manage the paths for the computers, the users and the projects. This tool cares about the different Matlab versions also, e.g. it adds workarounds for modern Matlab features like the 2nd and 3rd input for find when Matlab 6.5 is used.
So if someone includes a new folder for a project, other users of the projects have to call
initialize ProjectName
only and the path is set automatically.
This allows to define further paths depending on the machine or user, e.g. if some user data are stored on a local machine: If you run the initialization on this machine, the path to the data is defined accoringly, while on other computers the network path is used.
This can be used as a cheap version management also. This allows for an easy direct comparison of the results:
initialize projectA v1 % includes "N:\MFiles\ProjectA\Base_v1;Tools_v1;Graphics_v1"
run_projectA
initialize projectA v2 % Removes all folders insider N_\MFiles\ProjectA
% includes "N:\MFiles\ProjectA\Base_v2;Tools_v2;Graphics_v1"
run_projectA
While the "Base" and "Tools" folder have been changed, the graphic output is the same in this example.
In a multi-user/project/computer environment such a method for the folder management is very useful - I would say obligatory. Then the pathdef.m file contains one user-defined folder only: The one of the project management system.
  1 Comment
Shiryaev
Shiryaev on 16 Jun 2015
In this case the four machines are all being used by the same user. It is desired by this user, myself, that all matlab related files be available to any of the four machines at the same time. There are no local deviations. This is why the cloud based solution is so convenient. Folder "work" on my cloud contains all matlab related files, and it is also the default start folder on all four machines. No changes ever have to be copied. This is perfect, except that when the folder structure of "work" changes, the pathdef file on each machine has to be changed. This is not hard to do in Matlab: 1) make folder changes in Windows 2) set matlab path to default 3) reset matlab path to reflect new version of "work" folder. It is just a hassle that this needs to be done on four machines. The solution you have proposed above does not come with implementation files that you refer to. Also it does not answer the problem as posed. Your Answer is rejected.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!