How to loop 100 txt files through a folder

3 views (last 30 days)
jahmunah vicnesh
jahmunah vicnesh on 16 Jul 2015
Edited: Stephen23 on 17 Jul 2015
Hi, I am completely new to matlab. I need help to load 100 txtfiles from one folder into matlab to extract features. Can I please know the step by step code to use to loop them using batch files?
  2 Comments
Bikram Kawan
Bikram Kawan on 16 Jul 2015
matFiles = dir('*.txt');
numfiles = length(txtfiles);
disp(numfiles)
mydata = cell(1, numfiles);
for k = 1:numfiles
mydata{k} = load(matFiles(k).name);
dataset=mydata{1,k};
disp(k)
%You other code to execute in this block
end
jahmunah vicnesh
jahmunah vicnesh on 17 Jul 2015
Thank you Bikram Kawan. Using the following code i can only create a matfile but I am not able to load all my 100 textfiles from my folder. Am i missing another code? cuurently when i use this command, dir('C:/users/my desktop/Normal EEG'(my folder), it lists down all 100 textfiles. From there i am not sure how to loop into my workspace. My sup said something about batch files and loop. Any help is greatly appreciated. Thanks a lot!

Sign in to comment.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 16 Jul 2015
  3 Comments
Walter Roberson
Walter Roberson on 17 Jul 2015
Bikram Kawan's reply shows looping and loading data.
jahmunah vicnesh
jahmunah vicnesh on 17 Jul 2015
Edited: Stephen23 on 17 Jul 2015
Thank you Walter Roberson for your reply. when i type the following command, I get this:
>> matFiles = dir('C:/users/jamie_000/desktop/Normal EEG/*.txt');
>> numfiles = length(txtfiles);
Undefined function or variable 'txtfiles'.
when i type this command, it lists all the 100 files in the folder, after which I am not sure how to proceed to loop as all the codes i try do not work or have some error. I think I am doing something wrongly but can't figure out what. Each text doc has 4097 numbers.Pls help. Im really stuck :'((
dir('C:/users/jamie_000/desktop/Normal EEG/*.txt');
O001.txt O011.txt O021.txt O031.txt O041.txt O051.txt O061.txt O071.txt O081.txt O091.txt O002.txt O012.txt O022.txt O032.txt O042.txt O052.txt O062.txt O072.txt O082.txt O092.txt O003.txt O013.txt O023.txt O033.txt O043.txt O053.txt O063.txt O073.txt O083.txt O093.txt O004.txt O014.txt O024.txt O034.txt O044.txt O054.txt O064.txt O074.txt O084.txt O094.txt O005.txt O015.txt O025.txt O035.txt O045.txt O055.txt O065.txt O075.txt O085.txt O095.txt O006.txt O016.txt O026.txt O036.txt O046.txt O056.txt O066.txt O076.txt O086.txt O096.txt O007.txt O017.txt O027.txt O037.txt O047.txt O057.txt O067.txt O077.txt O087.txt O097.txt O008.txt O018.txt O028.txt O038.txt O048.txt O058.txt O068.txt O078.txt O088.txt O098.txt O009.txt O019.txt O029.txt O039.txt O049.txt O059.txt O069.txt O079.txt O089.txt O099.txt O010.txt O020.txt O030.txt O040.txt O050.txt O060.txt O070.txt O080.txt O090.txt O100.txt

Sign in to comment.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!