addpath from a different subfolder of the same parent directory
66 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luis J Gilarranz
am 23 Okt. 2019
Kommentiert: Luis J Gilarranz
am 23 Okt. 2019
I have a matlab script in the following directory
PROJECT/JHON/script.m
And I need to acess filess that are in the following directory
PROJECT/MARIA/
If the "MARIA" folder were inside "JHON" it would be as easy as addpath('MARIA'), but I cannot change the folder structure, and I need to perform certain operations that require the path to be added to the search path.
Cheers!
0 Kommentare
Akzeptierte Antwort
Guillaume
am 23 Okt. 2019
Data folder should never be added to the search path. It's dangerous (you may change what functions are in scope) and there's no need to anyway.
All matlab IO functions accept full paths of data file for import/export. It's much better to specify the full path of files. That way they can be anywhere you want, even on a network folder.
So, instead of something like:
%code that relies on the folder where mydatafile.txt resides to be on the path or be the current folder
data = csvread('mydatafile.txt'); %actual function used for importing is irrelevant
use
%code that works regardless of location of folder. Doesn't need to be on the path or be the current folder
folder = 'C:\somewhere\somefolder'; %location of mydatafile.txt. Could even be remote
data = csvread(fullfile(folder, 'mydatafile.txt'));
5 Kommentare
Guillaume
am 23 Okt. 2019
Assuming your current folder is PROJECT/JHON, then the relative path to PROJECT/MARIA/ is
addpath('../MARIA');
or you could still build a full path:
addpath(fullfile(pwd, '..', 'MARIA'));
I don't see how this solve your problem though since you still have to ensure that the current folder is indeed PROJECT/JHON/ on whichever computer is used.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Search Path finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!