I've searched around and found some potential solutions for my problem but have been unable to implement the code.
Essentially, I have one directory with 32 sub-folders. Each of the 32 sub-folders has 4 files inside (.mat with 1 row and a few million columns each). My variable of interest is called data (see bellow in code).
I need to access all 4 .mat files inside a subset of the sub-folders and append/concatenate them into a single big matrix. More, every group of 4 files in every sub-folder should be next to each other in the end matrix.
Also, the names of the sub-folders and the files within are known:
Folders = TT1, TT2, etc.
Files = TT1ch1, TT1ch2, TT1ch3, TT1ch4; TT2ch1, TT2ch2, TT2ch3, TT2ch4, etc.
I would also need to specify in the code which sub-folders to actually open and read the 4 files from. Not all need to be read at all times. Until now I have this:
TTs = [1,2,3,4,5]; % List of sub-folders to use.
for i = TTs;
addpath(strcat('TT',num2str(i)));
cd (strcat('TT',num2str(i)));
for w = 1:4; %get data from the 4 files
load(strcat('TT',num2str(i),'ch', num2str(w), '.mat'));
allChs(w,:) = data(1,:); %concatenate into one matrix
end
cd ..
rmpath(strcat('TT',num2str(i)));
end
With this code I'm able to read the data from 4 files of a given sub-folder and copy it to a new matrix (allChs). Yet, when I try to add code to go through all folders I simply overwrite what I have...
I've tried different things but am quite stuck at this stage. Any help would be dearly welcome.
Cheers, Oiko