I have a long list of subject folders (~70) I need to pull an individual summary file from each folder, scan and write the information to a new overall summary file.
I have most of the processing code written, however I am having issues automating the opening of each folder and extracting the data. I would prefer not to individually select each file.
Folder names are 'SubjectXX' and within each is a .txt file called 'Summary_SubjectXX.txt' along with other unnecessary folders.
I am using uigetdir to select the parent folder, but I cant seem to navigate into each folder after establishing the directory. Code I have so far is:
%%%
subjects_folder = uigetdir('*.txt'); cd(subjects_folder); list_of_subject_folders = dir(subjects_folder); for i = 3:numel(list_of_subject_folders) file_to_process = dir('Subject[0-9][0-9]*'); %This line seems wrong to me
subjectID = regexp(file_to_process, 'Subject[0-9][0-9]*','match'); fid = sprintf('%s_%s', 'Summary', subjectID{1}); fID = fopen(fid, 'r'); scanned_data = textscan(fID, ['%*s', '\t', '%s', '\n']); data_to_print = [subjectID, scanned_data{1, 1}(2:22)]; fclose(fID); cd ../ end
%%%
I feel like I am just missing a simple step in identifying the folders, however I am relatively new to MATLAB and cannot seem to figure it out with just the 'help' function.
I appreciate any help or advice!
Best Answer