How to read / import specific data from a txt file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to read / import specific data from a txt file

Danielo
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
different stuff).

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



<https://octave.1599824.n4.nabble.com/file/t373441/ZDJF1Qm.jpg>



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: How to read / import specific data from a txt file

Juan Pablo Carbajal-2
Hi Danielo,

Have you tried commenting out (with #) the header lines and just
loading into Octave?

load myfile.txt

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.

Cheers