Loop through files in a folder in matlab

Fantastic Mr Fox picture Fantastic Mr Fox · Jul 24, 2012 · Viewed 102.8k times · Source

I have a set of days of log files that I need to parse and look at in matlab.

The log files look like this:

LOG_20120509_120002_002.csv
(year)(month)(day)_(hour)(minute)(second)_(log part number)

The logs increment hourly, but sometimes the seconds are one or two seconds off (per hour) which means i need to ignore what they say to do loadcsv.

I also have another file:

LOG_DATA_20120509_120002.csv

which contains data for the whole hour (different data).

The overall objective is to:

 loop through each day 
     loop through each hour
         read in LOG_DATA for whole hour
         loop through each segment
             read in LOG for each segment
                 compile a table of all the data

I guess the question is then, how do i ignore the minutes of the day if they are different? I suspect it will be by looping through all the files in the folder, in which case how do i do that?

Answer

Isaac picture Isaac · Jul 24, 2012

Looping through all the files in the folder is relatively easy:

files = dir('*.csv');
for file = files'
    csv = load(file.name);
    % Do some stuff
end