Merge multiple .mat files based on specific file name structure

Hi, I have over 300 .csv files that I converted to .mat files. The mat files have a specific naming culture like AB10*.mat AB11*.mat, ...AB31*.mat. So it is AB followed by day of the month followed by time.mat. I am trying to merge the files based on the date. So all files named as AB11*.mat should be able to merge. Edit: What would be the general procedure to do this?

6 Comments

I went through that. The file is named in a manner such as AB111309- AB is sequence, 11 is the date, and 1309 is the time. I have 10 files starting with the name AB11. How can I merge all of them, and the other 290 files which follow a similar format?
@Mehul Garg: what do you mean by "merge": what do you want the output to be: one big .mat file, a text file, some other kind of file, a big variable in MATLAB memory, or a sequence of images displayed as a sequence of frames (like film) ?
Each file has about 3000 rows of data. I want to append the existing mat file, so just one file has 3000*10 rows of data. So yes, just one big mat file for each day. In the end the 300 mat files should be condensed into 30/31 based on the month of data. I am sorry for the vagueness in my questions and I thank you for your patience.
@Mehul Garg: Can you please upload a few sample files by clicking the paperclip button.
files = dir('AB11*')
The above line should list the files strating with AB11.

Sign in to comment.

 Accepted Answer

Something like this might get you started:
for k = 1:31
fmt = sprintf('AB%d*.mat',k);
S = dir(fmt);
N = {S.name};
... merge files here
end
How to "merge" depends on what you mean by "merge": are you wanting to vertically concatenate the data, or horizontally concatenate the data, or add new fields to an existing structure, or sum the data values, or ...

More Answers (0)

Products

Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!