0

I need to read 8760 files (365 days * 24 hours = 8760) of small size (60 kb) and aggregate values and take average of some values.

Earlier, I have used the below stated code for reading *.csv files:

for a=1:365
for b=1:24

s1=int2str(a);
s2=int2str(b);
s3=strcat('temperature_humidity',s1,'_'s2);

data = load(s3);

% Code for aggregation, etc

end
end

I was able to run this code. However now the file name is little different and I am not sure how to read these files.

Files are named like this:

2005_M01_D01_0000(UTC-0800)_L00_NOX_1HR_CONC.DAT

where M = Month, so the values are 01, 01, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12; D = Day, so the values are 01, 02, 03, ..., 31; Hours is in this format: 0000, 0100, 0200, ..., 1800, ..., 2300.

Please take a look at the attached image for file name . I need to read these files. Please help me.

Thank you very much.

2
  • Do you need to extract date and time from the filenames or do you just want to read all of the matching files in arbitrary order? Commented Apr 17, 2014 at 7:32
  • Hi @Deve, I just want to read files in sequential order. If file is named like "temperature_i_j.csv" where i = 1 to 365 and j = 1 to 24, I am able to read it but now files are named like "M01_D01_0000_Conc.dat", here immediate 2 numbers on right of M varies from 01 to 12, immediate 2 numbers on right of D varies from 01 to 31 and hour changes from 0000 to 2300. I do not know how to incorporate 01, 02, 03, 0000, 01000 as file name in a for loop for reading files. Commented Apr 17, 2014 at 15:09

1 Answer 1

1

I would use dir:

files=dir('*.dat')

Or you can construct the filenames with

name = sprintf('%d_M%2d etc.',...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.