Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB add path temporarily [duplicate]

Tags:

matlab

I'm working on a project containing some subprojects. Each subproject is located in a own folder.

projDir/subProj1
       /subProj2

and so on. Each subproject is a standalone running project. But now I want to use some functions of i.e. subProj1 in subProj2. But the functions in subProj1 should not be visible in general. So it is no good idea, to add the subProj1-path to the MATLAB-Path generally. Hence, I want to add this path in my .m-file stored in subProj2 and after finishing this script, the path should be removed (automatically) by it's own. Is there any possibility, to add a path temporarily to the MATLAB-path variable?

like image 599
paul_schaefer Avatar asked Mar 10 '15 10:03

paul_schaefer


2 Answers

The addpath function only adds the files/folder to your path for the current Matlab session, assuming you don't call savepath. You also might find the genpath function helpful if you want to add subfolders.

like image 61
Dan Avatar answered Sep 29 '22 12:09

Dan


You can use path(path_to_add,path) to add a path to the current path variable. Unless you do savepath you won't affect the global path.

I would do path(strcat(pwd,'\subProj1',path) etc. in the config .m script you have.

like image 36
tuna_fish Avatar answered Sep 29 '22 14:09

tuna_fish