Matlab forgets new paths I add
24 次查看(过去 30 天)
显示 更早的评论
I have been trying to add some paths to matlab but even though I save the changes, the changes are not present when I reopen matlab. Can this be related to that I have both 2022a and 2024a versions?
Thank you for any support you can provide,
Best regards,
Paris
0 个评论
采纳的回答
Star Strider
2024-10-12
@Paris — You probably need to create (or change) your startup fiie. I have one (startup.m) I have been using for decades, although changed from time to time to reflect changes in MATLAB.
It creates and defines the path each time MATLAB loads:
pathmat = path;
My_Path = userpath;
My_Dir = FEF_Path;
My_Work_Dir = genpath(My_Dir);
addpath(My_Work_Dir, '-end');
That is the current version. Something like it should work for you. (My startup.m filee has some other stuff as well, however those lines are the essence of the path creation part of it.)
The startup.m file itself needs to exist as:
C:\Users\<username>\Documents\MATLAB\startup.m
in Windows. (That may be diifferent in other operating systems. Check the documentation.)
.
3 个评论
Star Strider
2024-10-13
I should have stated that code as:
pathmat = path;
My_Path = userpath;
My_Dir = My_Path;
My_Work_Dir = genpath(My_Dir);
addpath(My_Work_Dir, '-end');
instead, then it would have made more sense.
My apologies for the confusion.
更多回答(2 个)
Shivam Gothi
2024-10-12
编辑:Shivam Gothi
2024-10-12
As per my understanding, you want to automatically include certain directories in your MATLAB search path, when MATLAB starts.
You can include the directory to the search path by using "path" command. You can type below command to open documentation of "path()" function.
doc path
In order to automatically include the directories in the search path when MATLAB starts, place the "path()" command inside a "startup.m" file. This file must always be available when MATLAB starts: it must either be in the directory in which MATLAB is started or in a directory already in the MATLAB path.
Refer to the below MATLAB answer link to get more clear idea of how to implement it.
I hope it helps !
3 个评论
Shivam Gothi
2024-10-12
I tried to add path as shown by you in the above image. I am using R2024a version and in my case, it is saving the path properly.
I have some questions:
- Which version of MATLAB are you using?
- The second image attached by you is after reopening the MATLAB or it is executed in same command window (without closing MATLAB) ?
- Could the newly added paths be restricting MATLAB to save or edit files in those directories?
- Have you tried to add other directories from (C:) drive itselves ?
Steven Lord
2024-10-12
What did you run between those two pictures of the Path Tool? It almost looks like you ran (or a function you executed ran) path(genpath) or restoredefaultpath between those two pictures.
If so, unless you have a very, very good reason for manipulating the path you should probably remove those commands from the code. [If you're adding directories to the path so you can read data files stored in those directories, there are alternate approaches that don't require manipulating the MATLAB Search Path, like creating fully qualified paths to those files using fullfile and passing those fully qualified names into the functions that read those data files.]
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!