Why is my modified path not saved in MATLAB?
Mostra commenti meno recenti
I am modifying my MATLAB path by using either the "Set Path" button in the toolbar, or by using the "addpath" and "savepath" commands in the MATLAB Command Window. However, when I exit MATLAB and restart it, the MATLAB search path does not reflect the changes that I had made.
Why are my MATLAB path modifications not saved in the new session of MATLAB?
Risposta accettata
Più risposte (1)
Jan
il 6 Giu 2019
It is safer to work without admin privileges to avoid an accidental modification of Matlab's toolbox functions. A drawback is, that you cannot modify <matlabroot>\toolbox\local\pathdef.m file in without admin privileges. This file defines Matlab's path for all users on the local machine, so it is questionable if it should be used at all on a multi-user machine.
The current method to select the first pathdef.m file in the path at startup is working and can catch all needed situations, as long as the user has the privilege to modify the pathdef.m file in the installation folder and does this carefully. For users without admin privileges or with a less careful programming style (adding folders on top of Matlab's path - bad idea), the current method is not optimal. If Matlab is started in a specific folder, which contains a pathdef.m file also, there is a risk of confusion.
I solved the problem by opening Matlab once with admin privileges and add one folder at the bottom of the path:
addpath('D:\MFiles\Inits', '-end');
savepath;
This is equivalent to editing the path in pathtool and pressing "Save".
This folder D:\MFiles\Inits\ contains files, which appends the user defined folders to Matlab's path. This allows to work e.g. with projects also and a kind of version control is possible also.
It would be smarter, if Matlab uses <matlabroot>\toolbox\local\pathdef.m at first and includes the userpath (see https://www.mathworks.com/help/matlab/ref/userpath.html ) automatically, and then appends the folders defined in userpath/pathdef.m to the path.
Another option is to insert the user-defined changes of the path inside the startup.m function, which is called automatically from matlabrc.m on startup. Here the user has the full control without admin privileges also. So actaully there is no need to modify pathdef.m at all, but this happens in pathtool and so it became a standard.
See also these tools to manage the path:
- https://www.mathworks.com/matlabcentral/fileexchange/65974-matlab-project-file
- https://www.mathworks.com/matlabcentral/fileexchange/23218-project-manager
- https://www.mathworks.com/matlabcentral/fileexchange/66784-sessionmanager
- https://www.mathworks.com/matlabcentral/fileexchange/39425-restore-project-status-for-selected-project
Categorie
Scopri di più su Search Path in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!