How to add a folder permanently to matlab path?

864 vues (au cours des 30 derniers jours)
Dishant Arora
Dishant Arora le 14 Fév 2014
Modifié(e) : Walter Roberson le 21 Avr 2024 à 23:16
I am using addpath to add specified folders to matlab path, but it removes the folders from the matlab path everytime the application closes. I want to add that particular folder permanently to matlab path, so that I don't have to add it again everytime i run the application. How can it be done??
Any help is appreciated.
  1 commentaire
Ken Garrard
Ken Garrard le 21 Avr 2024 à 21:46
Modifié(e) : Walter Roberson le 21 Avr 2024 à 23:16
The persistence of the path has been a problem for many releases. Savepath and the save button in the setpath toolbar utility have not worked correctly in every release for many years.
1) If you're using Windows you could try using the MATLABPATH environment variable.
2) You could edit the pathdef.m file even though this is not recommended.
3) I modify the startup.m file to add 64 folders to the search path. The file kpath.mat contains a structure with a single variable that is a character vector of the full path to each of 64 folders that I want to add to the path separated by ';'.
p = load('kpath.mat');
addpath(path(p.kpath,path));
clearvars p;

Connectez-vous pour commenter.

Réponse acceptée

Thomas
Thomas le 14 Fév 2014
Modifié(e) : Thomas le 14 Fév 2014
You can put the addpath statement to startup.m
  2 commentaires
Roy Axford
Roy Axford le 31 Jan 2020
This method works best and I have adopted it. Using it makes it unnecessary to maunally add the desired paths and folders at the beginning of a MATLAB session, thereby saving a step.
Ronald Modesitt
Ronald Modesitt le 20 Déc 2020
I am also using this method for my user written functions.

Connectez-vous pour commenter.

Plus de réponses (2)

Jan
Jan le 14 Fév 2014
addpath YourFolder
savepath
  2 commentaires
Aysu Soezbir
Aysu Soezbir le 7 Déc 2023
best and easiest advice guys
Tzu-Cheng Hsueh
Tzu-Cheng Hsueh le 11 Déc 2023
Best answer, thanks! Just to remind that all the folder name should not have space between or it could get wrong

Connectez-vous pour commenter.


Luís Fresco
Luís Fresco le 3 Juil 2019
On Matlab's toolstrip, you may find the option "Set Path" which allows to select one directory (or also its subfolders) and save it permanently to Matlab's "search path".
Untitled.png
  2 commentaires
Roy Axford
Roy Axford le 31 Jan 2020
This solution has merit in that it takes advantage of the tool strip and it works. But it is not permenant. It must be repeated each time I restart MATLAB.
adrieto
adrieto le 29 Mar 2020
I used the solution proposed by Luis Fresco. It worked (I didn't need to do it every time I restarted MatLab). Into the default search path I added a new folder with some functions in it. I put "Add with subfolders", selected the main folder and when a new window pop-up, just accept that.
I wrote a script in the main folder which uses a function into the subfolder, and it worked just fine. I restarted MatLab to check if the solution was permanently, and it is.

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by