Matlab forgets new paths I add
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paris
el 12 de Oct. de 2024
Comentada: Star Strider
el 13 de Oct. de 2024
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 comentarios
Respuesta aceptada
Star Strider
el 12 de Oct. de 2024
@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 comentarios
Star Strider
el 13 de Oct. de 2024
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.
Más respuestas (2)
Shivam Gothi
el 12 de Oct. de 2024
Editada: Shivam Gothi
el 12 de Oct. de 2024
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 comentarios
Shivam Gothi
el 12 de Oct. de 2024
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
el 12 de Oct. de 2024
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.]
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!