MATLAB: How to load multiple dat files of different name pattern and from different directory consecutively to do something

loading file sequentially

Hi, I have some dat files of row*Column( 9999*10 )of names:
dir1/a_0.1_1
dir1/b_0.1_2
dir1/c_0.3_1
dir1/c_1.5_1
dir2/a_0.1_1
dir2/a_0.5_1
Now How can I load and recall then sequentially to do something? is there any short cut for loop for this specially when they are in different folder? Thank you

Best Answer

You can use this FEX submission. Download it and place it in MATLAB path. To get the list of all .dat files, use it as follow
files = subdir('*.mat');
this will work, if you are present in the top folder of dir1, dir2 etc. This will give you name and path of all the '.dat' files in the subfolder. Then read and process like this
data = cell(1, length(files))
for i=1:length(files)
filename = files(i).name;
% load your file here, use load(), tableread() or any appropriate function depending on the type of data in .dat files
data{i} = readData; % save your read data or do any other processing
end