set paths disappear after restart

Hello together,
latley it occures to me, that I loose paths that I have set in matlab. I use File -> set Path... -> add Folder... choose the relevant folder and save it. The new added path works until i restart Matlab. Then the new path is disappeared from the list. And it seems, that all the previous added paths are deleted aswell.
Can't tell where the problem is, because thats the way i always did it.
Does anyone know how it is possible, how the path list is deleted? Is there a file, where it is stored?
Thank you for your effort.
Rafael

1 Comment

I have noticed, that when i set the path to default, all from me added path disappear, but when i restart matlab they are back again. So all my changes are temporarly and not permantent altough i save it. It seems to me, that matlab reads a different "path-file" when restarted.
How can i fix this?

Sign in to comment.

 Accepted Answer

Jan
Jan on 1 Dec 2016
The path is stored in the file pathdef.m inside Matlab's program directory. If you do not work with admin privileges (as recommended), you do not have write permissions for this file and all changes of the path are temporarily only. This is useful on a multi-user system, because the pathdef.m file belongs to all users.
I've added one folder to the path in pathdef.m file, which contains a function, which adds the user-defined paths temporarily depending on the user and current project. This works reliably and flexible. Alternatively you can create a startup.m and finish.m file to store the current path persistently between sessions using setpref and getpref.

6 Comments

Thank you.
This somehow makes sense. When i start Matlab as admin i see all relevant paths and i am able, to add new paths which are permanent. The command
which pathdef
gives me the path C:\Users\x\Document\MATLAB\pathdef.m
When i start matlab, by opening a simulink model (.mdl) i don't see all relevant paths.
The command
which pathdef
gives me the same path C:\Users\x\Document\MATLAB\pathdef.m
What does this reply:
which pathdef -all
Is the User folder part of the path and if so, does it appear before matlabroot\toolbox\local, where (as far as I remember) the system-wide pathdef.m is stored?
Rafael Kübler
Rafael Kübler on 2 Dec 2016
Edited: Rafael Kübler on 2 Dec 2016
which pathdef -all replys:
C:\Users\x\Documents\MATLAB\pathdef.m
C:\Program Files (x86)\MATLAB\R2011a\toolbox\local\pathdef.m % Shadowed
the result is the same, when i run Matlab as admin or when i start matlab by opening a model.
So yes. The User folder appears before matlabroot. Is this correct? Or should it be the other way round?
When i run Matlab as admin, i am able, to add paths to. They get stored in C:\Users\x\Documents\MATLAB\pathdef.m
But when i run matlab by opening a model, where its not running as admin, it seems to load another pathdef.m. Not C:\Program Files (x86)\MATLAB\R2011a\toolbox\local\pathdef.m nor C:\Users\x\Documents\MATLAB\pathdef.m, because it has paths in it, that occour in none of these pathdef.m files
so i fixed it now, by deleting the user path and changing the savepath to the matlabroot C:\Program Files (x86)\MATLAB\R2011a\toolbox\local\pathdef.m. Now i have just one pathdef.m, which gets loaded with or without admin. Since i am the only one using that pc it schould not be a problem.
Thank you Jan for your support.
In 2018 this has to be nonsense. If I set the path and save it it should be restored everytime I start MatLab.
Agreed. I save pathdef.m to my startup folder. And when I use the command "which pathdef" after startup, it points to that folder. But MATLAB does not use it to set the path. I fixed this by adding the command "path(pathdef)" to my startup folder, so the path is set to what I save it to the last session. But MATLAB should be doing this automatically.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!