MATLAB: Batch processing (automating code processing)

MATLABprocessing data

Hi all,
I have a question about running a code on multiple datasets. I have seen many examples and methods, but unfortunetly, they did not work for me.
I have over 500 data sets, all have same structure of data but different numbers (arranged in sruct.array) so they are already in .mat form.
Those .mat files are stored on my computer as follow :mainfolder > 5 subfolder > N number of subsubfolder > 15 .mat files
Thus, for each subsusbfolder, there is 15 .mat files.
So, basically I want to process those .mat files by calling a function on all of those data sets automatically, but not really sure how to do so especially that I need a for loop to navigate my subfolders and subsubfolders to reach to the .mat files.
Any help would be appreciated.

Best Answer

This will give you the structure containing all .mat files.
File_Struct = dir('**/*.mat');
Edit:
Use name and folder to get the full path to each .mat file.
File_Struct = dir(fullfile(myFolder, '**/*.mat'))
File_Path = cell(size(File_Struct,1), 1);
for ii = 1 : 1 : size (File_Struct,1)
File_Path {ii} = fullfile(File_Struct(ii).folder, File_Struct(ii).name);
fprintf(1, 'Now reading %s\n', File_Path {ii});
load(File_Path {ii}); %this is changed
data=myfunc1(data)% calling my function1
data=myfunc2(data)% calling my function2
Processed_Data(ii).Value = data; % structure
end