How to read / import specific data from a txt file
I have around 2000 txt files following the same structure containing
summarized information from different weather stations. I would like to
create a matrix extracting some specific fields from them, one column with
the name of the file, another with the coordinates and another with the
values at the lower part of the file (they are yearly mean values of
Here is attached a screenshot of one of them. I’ve imported to excel and
found out that they can be imported as tab delimited files but that’s just
nice to know information. The txt files are the monthly mean data from the
yearly-by-minute data on the CVS files that they are on screen.
I took a Matlab /Octave class but we never really cover working with
external files other than matrix files. I would appreciate some help with
the subject. Thanks
Re: How to read / import specific data from a txt file
Have you tried commenting out (with #) the header lines and just
loading into Octave?
If that works then you just need a short script (maybe using sed) to
comment all your files automatically.
If that doesn't work because your data is not numeric only, you can
try the functions dlmread, or more flexible, csv2cell from the IO
package (pkg install -forge io; pkg load io).
If Excel can load your data, then csv2cell can also do it.