Matlab forgets new paths I add

조회 수: 24 (최근 30일)
Paris
Paris 2024년 10월 12일
댓글: Star Strider 2024년 10월 13일
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

채택된 답변

Star Strider
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
Star Strider 2024년 10월 13일
As always, my pleasure!
Star Strider
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
Shivam Gothi 2024년 10월 12일
편집: Shivam Gothi 2024년 10월 12일
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
Shivam Gothi
Shivam Gothi 2024년 10월 12일
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 2024년 10월 13일
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.

댓글을 달려면 로그인하십시오.


Steven Lord
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.]
  댓글 수: 1
Paris
Paris 2024년 10월 13일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by