MATLAB: Import a thousand of AscII files, combine them in one XYZ text file and export them again as one text file

combine ascii files in one xyz text file

HI,
I have a thousands of ASCII files which start with the name "CDR_19830101z.asc" and end with the name "CDR_20160101z.asc". I am trying to call them all in Matlab, and export them as one combined XYZ text or excel file.
These files are averages rainfall per day, of a specific area. The X and Y value are the same of all the files. The only value which changes is the Z value which consider the the average rainfall per day. So I am trying to build a graph between the time and rainfall of each square within this study area.
The file CDR_19830101z.asc format is:
ncols 6
nrows 4
xllcorner 41.500
yllcorner 35.500
cellsize 0.25
NODATA_value -99
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00
The last file "CDR_20160101z.asc" format:
ncols 6
nrows 4
xllcorner 41.500
yllcorner 35.500
cellsize 0.25
NODATA_value -99
1.19 2.14 0.89 2.86 3.18 5.77
1.24 4.41 1.39 2.42 2.87 4.51
1.27 1.82 1.29 1.60 1.24 2.88
1.37 2.43 3.26 2.44 2.80 2.13
I appreciate your help and time.
Thanks, Majid
…[cleaned up/formatted data–dpb. NB: Use the {}Code button to format such lines in future]…

Best Answer

projectdir = uigetdir('Select a directory');
dinfo = dir( fullfile(projectdir, '*.asc') );
filenames = fullfile( projectdir, {dinfo.name} );
for K = 1 : length(filenames)
this_file = filenames{K};
now convert the one file named by this_file
end