Clear Filters
Clear Filters

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

4 views (last 30 days)
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]...
  2 Comments
dpb
dpb on 4 May 2017
Are all dates present or are there missing files? IOW, do you need to store the date info in the file or can it be inferred from the position knowing first entry date/time?
Just to be certain we know what we're talking about, I presume the 24 entries are annual totals for a given geographical subsection within the total area as given by the LL corner coordinates?
Majid Mohamod
Majid Mohamod on 9 May 2017
Edited: Majid Mohamod on 9 May 2017
There is no missing in the data. Actually I found the script which load the Raster ASCII and convert it to XYZ.csv file. But I want to modify this script to be as the following:
Apply this script on different files (12000 files) and auto save with any name (It's not important the name for now) with format csv.
I was thinking that if we can use the loop fucntion in MatLab and apply this script on each file one after one!
The script which I use is:

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 May 2017
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
  21 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!