I seem to be constantly replacing my old MATLAB release with a new one. So generally two releases a year, plus two beta versions per year. Each time, I need to update the search path for the new release. In my case, this means adding several dozen of my own toolboxes, plus a few more that I have downloaded from the file exchange. Some of them go on the end or the beginning of the path, as is my preference. Honestly, this takes up some time to redo all of those directories, because they do not all lie in the same place, and some of those directories have subdirectories that I do not want on the path. So I end up spending some time to redo the new search path. In fact, this is the main reason why I am sometimes slow in downloading a new release.
The solution should be for MATLAB to offer a way to export your search path from the old release as a file, then be able to import those path directories into the path of the new release. This should be easy to do, but I've not yet seen anything in the path tools from MathWorks to do it. So I wrote my own tool to solve the problem.
1. In your old MATLAB release, run the export_search_path function. It will create two new files in the current directory. One is a .mat file, and the second an m-file called import_search_path.
2. Start the new MATLAB release, then CD to the same directory those files were saved to.
3. Run the import_search_path function from the command line.
Your new release will now have all of those directories added to the search path, and it will have taken you only a few seconds to accomplish the entire conversion. I've been careful to add those directories to your path in the same order they were before. All you need do now is delete the import_search_path.m file, and the __matlab__search__path__.mat file from that directory.
EXPORT_SEARCH_PATH takes apart your current search path, looking for directories that are not under the MATLABROOT directory structure. Then it subsets them into those that came in front of the MATLABROOT directories, and those that fall at the end. Any that fell in the middle for some reason, it adds to the end too.
John D'Errico (2021). export_search_path (https://www.mathworks.com/matlabcentral/fileexchange/50087-export_search_path), MATLAB Central File Exchange. Retrieved .
obviously you'd want to replace the fileseparator according to the system at hand.... useful for people who use windows, Mac/Unix mixed environments.
great addition, but maybe you could add some functionality which I'm currently facing:
I try to use matlab on several computers using an external drive. How about saving the paths relative to the 'export_search_path' file and then add this function to the primary directory which contains all matlab files. If executed it could get the current path, remove everything up until the current directory and when importing the paths at any other computer, it would simply get the new absolute path of the execution directory and add the appropriate subdirectories.
This combined with the functionality of leaving out all matlab packages belonging to the local version would allow to use all your matlab directories on a portable disk, usb-stick or a webdrive.
I haven't gotten around to write this myself as I thought somebody had already implemented it. I think if you added this functionality many would use it.
Saves me time, thanks.
I would only point to this comment in the pathdef.m file:
% DO NOT MODIFY THIS FILE. IT IS AN AUTOGENERATED FILE.
% EDITING MAY CAUSE THE FILE TO BECOME UNREADABLE TO
% THE PATHTOOL AND THE INSTALLER.
So you might want to take care when playing there.
All the paths are defined in pathdef.m; it can be opened via "edit pathdef.m" in the command line. The simplest way, and the way I have been using, is to copy and past the paths of my own toolboxes and code pieces.
Share with you.
No. You did not read what the help and description says. It creates that m-file for you. Out of thin air so to speak, WHEN you use the export_search_path function.
The reason is that when you move to the new MATLAB release, the presumption is that you will have no downloaded files on your path. So export_search_path creates that file in the current directory.
In fact, you can see the code for import_search_path inside the export_search_path function. So it IS provided, as I said. You just don't see it until you need it and can use it.
Of course, you do need to be in a directory where MATLAB will have write access.
import_search_path file missing
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!