Matlab forgets new paths I add

25 vues (au cours des 30 derniers jours)
Paris
Paris le 12 Oct 2024
Commenté : Star Strider le 13 Oct 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

Réponse acceptée

Star Strider
Star Strider le 12 Oct 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 commentaires
Star Strider
Star Strider le 13 Oct 2024
As always, my pleasure!
Star Strider
Star Strider le 13 Oct 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.

Connectez-vous pour commenter.

Plus de réponses (2)

Shivam Gothi
Shivam Gothi le 12 Oct 2024
Modifié(e) : Shivam Gothi le 12 Oct 2024
Hello @Paris,
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 commentaires
Shivam Gothi
Shivam Gothi le 12 Oct 2024
Hello @Paris,
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 ?
Paris
Paris le 13 Oct 2024
hi @Shivam Gothi, I managed to solf the issue, I think my startup.m file was changed by a simscape course folder which included a script with the same name.

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 12 Oct 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.]
  1 commentaire
Paris
Paris le 13 Oct 2024
I did not run anything between the two pictures, I just opened and closed matlab. Somehow my startup.m file was changed, and I think this was causing the issue. I have resolved it now based on another comment.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by