How do I import and read multiple text files with the same name from different folders
Show older comments
Hi,
I'm a beginner with matlab and struggling with opening and importing a large set of data. I have a folder DATA with subfolders P01, P02, P03 etc, in each subfolder 10 text files and i would like to open and read 1 txtfile from each subfolder named RESULTS_TRIALS. The data is 19 by 7 and i have 150 participants (P01 - P150), so would like to make a data array of 19x7x150.
I want to make a for loop to direct to all those different folders and importing 1 txt file per subfolder, however I have been struggling for a couple of days now and still dont have any clue how to make this happen.
Thanks in advance
4 Comments
Turlough Hughes
on 27 Nov 2019
Can you provide a sample of a RESULTS_TRIALS file.
annie
on 27 Nov 2019
Guillaume
on 27 Nov 2019
Oh! My answer will need modification for this type of text file as I assumed from the fact that you want a 3D array that all your data was numerical.
This sort of data should be stored in a table, which can't be 3D. In any case, you would be better off vertically concatenating all the results into just one table.Does the "ID" match the "Pxx" folder name? This would make the whole concatenation trivial, otherwise, I'd just add one variable to the table which is the source folder (assuming that you care about that information).
annie
on 27 Nov 2019
Accepted Answer
More Answers (0)
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!