- myfile.m refers to the myfile.m file in the current folder.
- ./myfolder refers to the myfolder folder in the current folder.
- ../myfolder/myfile.m refers to the myfile.m file in the myfolder folder, where myfolder is at same level as the current folder. Each repetition of ../ at the beginning of the path moves up an additional folder level.
How to load data from other directory?
1.367 views (last 30 days)
Stephen23 on 26 Nov 2015
Edited: Walter Roberson on 5 Feb 2021
This is explained quite well in the documentation:
Under the title "Absolute and Relative Path Names" there is the following information:
Some MATLAB functions also support relative path names. Unless otherwise noted, the path name is relative to the current folder. For example:
sarwat firoz on 14 Dec 2020
Case 1: If your file is in the same folder, as the file you are using to load the data.
Case 2: If your file is in a folder INSIDE your directory,
Case 3: If your file is one step OUTSIDE your directory,
Case 4: If your file is n step OUTSIDE your directory,
load ../../../../ ... ... ... ../../fileName;
% Please make as many as ../ as much as up you want to go in folder structure.
% Kindly ignore ellipsis.
Case 5: If you wanna go up 2 folders and from there you wanna enter a separate folder structure,
% Please use it the way you want.
P.S. Windows users can use either backward slash or Linux.
Titus Edelhofer on 26 Nov 2015
Edited: Titus Edelhofer on 26 Nov 2015
you simply need to remove the / at the beginning:
Note: replace "\" of course with "/" on Linux or OSX
Or use the generic functions:
% go to folders up the hierarchy:
upUpFolder = fileparts(fileparts(pwd));
% go into another folder
folder = fullfile(upUpFolder, 'subFolder');
% do whatever you like
Thorsten on 26 Nov 2015
Edited: Thorsten on 26 Nov 2015
Use '..' to refer to the folder that contains the current folder. To load ../folderName1/folderName1/filename.ext robustly on different OSs, use:
load(fullfile('..', 'folderName1', 'folderName2', 'filename.ext'))
you can add as much folderNames as you need.