How do I loop over .csv files with dates as the file name?

Hi all,
How do I loop over a folder of CSV files where the only difference in the file name is the date? I have every weekday between 04 Jan 2016 to 30 March 2016, and I need to do a for loop to load these .csv files. The weekday part seems to be confusing but I think it could still be simple. The files are names as follows:
GS_2016-01-05_525_888_statement_10.csv
Where the only thing that changes is the date 2016-01-05.
I just need to load each .csv in the loop and then use this loaded data inside an inner loop.
Cheers

Answers (1)

I suggest using matching dir pattern instead of building the specific file name (although that's easily-enough done by using the date-formatting functions)...
d=dir('GS_2016*statement_10.csv'); % return the yr 2016 files
for i=1:length(d)
x=csvread(char(d(i).name))); % read the file; convert the cell-string to character
...

Products

Asked:

on 21 May 2016

Answered:

dpb
on 21 May 2016

Community Treasure Hunt

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

Start Hunting!