rishiag
rishiag

Reputation: 2274

How to write relative path in MATLAB?

I need to read a group of dat files so when I do this it is working all right.

 list_of_files=dir(fullfile('/home/username/Desktop/Old/MTP/Generate/schemes/o33smnpimp/data/', '*.dat'));

The thing is I want to do this for number of schemes (like o33smnpimp) where every scheme folder has a data folder so I tried something like this but it's not working. What could be the problem?

list_of_files=dir(fullfile('../data/', '*.dat'));

My matlab file lies in o33smnpimp folder.

Upvotes: 1

Views: 5786

Answers (1)

Daniel
Daniel

Reputation: 36710

.. indicates the parent directory, . the current directory. your code looks in /home/username/Desktop/Old/MTP/Generate/schemes/ for the sub directory data, assuming your working directory is /home/username/Desktop/Old/MTP/Generate/schemes/o33smnpimp.

Use

list_of_files=dir(fullfile('./data/', '*.dat'));

or

list_of_files=dir(fullfile('data', '*.dat'));

Upvotes: 1

Related Questions