1

I have created a file list in a .txt file by using UNIX command. I need to do something on MATLAB as a loop by referring this file list. First I was stuck with importing filelist.txt into an array. My filelist.txt contains:

aa121001/121001ABC/1210010000/aa1.txt
aa121001/121001ABC/1210010000/aa2.txt
aa121001/121001ABC/1210010009/aa1.txt
aa121001/121001ABC/1210010009/aa2.txt
aa121001/121001ABC/1210010016/aa1.txt
aa121001/121001ABC/1210010016/aa2.txt
aa121001/121001ABC/1210010024/aa1.txt
aa121001/121001ABC/1210010030/aa1.txt
aa121001/121001ABC/1210010030/aa2.txt
...

In each aa1.txt or aa2.txt file, there are only numbers and no char. If I can import these strings into an array List, I want to code my program list this:

for k = 1:length(List)
myFolder = '/Users/LILI1234/Documents/DataSet';
file = fullfile(myFolder,List(k));
data = dlmread(file);
%do something 
end

So far it works for only one file (one line from the filelist.txt), but there are a lot of data files in different directories, so I want to do as a loop. Please let me know if you have any idea to help me. Thanks a lot!

1 Answer 1

1

You can import the file using List=importdata('filelist.txt') then the whole list will be in List cell array. From then you can call each file by List{k} like this

myFolder = '/Users/LILI1234/Documents/DataSet'; 
for k = 1:length(List)
    file = fullfile(myFolder,List{k}); 
    data = dlmread(file); 
    %do something
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.