I have more than 30 save setpath in Matlab and I want to remove them first and test something and later on, I want to add them back. What would be optimized way of achieving this. Is there a method to get the list of saved setpath and later on add paths in setpath by providing a list. I tried getnpath
and it returns the matlab toolboxes path.
Asked
Active
Viewed 157 times
1

Divakar
- 218,885
- 19
- 262
- 358

User1551892
- 3,236
- 8
- 32
- 52
1 Answers
1
Create a backup of paths in a mat file -
path_list = path;
save('paths.mat','path_list');
Do your thing of removing 30 saved paths by going to Set Path
option on the File menu
and do whatever testing you were looking to do.
Once done with the testing, now you wish to add back the deleted paths. So restore the paths from the backed up mat file -
load('paths.mat')
path(path_list)

Divakar
- 218,885
- 19
- 262
- 358
-
I want to extract the user defined path and want to remove them. If I follow your approach and first extract all path and then restore the default path and later on if I want to load the extracted path again then may be something will go wrong because matlab will have default path and extracted path will also contain default path. – User1551892 May 06 '14 at 11:32
-
MATLAB path is one big list of all the searchable paths that MATLAB uses. It can't distinguish between your `user defined path` or the path to it's in-built codes also called as `toolbox paths`. So once you do this `path_list = path; save('paths.mat','path_list');` and IF you don't tinker with that `mat-file`, you have all your toolbox and user defined paths safe in it. So, I would say just keep that `mat-file` in a safe place and you are set. – Divakar May 06 '14 at 11:38
-
I am think to write two script, first script will remove the user defined path from setpath and second script will add user defined path in setpath. I am thinking to use command 'rmpath' and 'addpath' – User1551892 May 06 '14 at 11:48
-
1Take care of issues of path staying good for next sessions or not with the commands like `savepath`. Read more about it on this [question](http://stackoverflow.com/questions/22013875/access-m-files-in-a-subfolder-without-permanently-adding-it-to-the-path) – Divakar May 06 '14 at 11:52
-
Yeah just adding on that - `addpath` stays good only for the current session and I am guessing so would `rmpath`, which means you won't be required to save paths as mat file. But still to be safe, you may test that out after saving as a mat file. – Divakar May 06 '14 at 11:56