help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading ASCII data files quickly


From: Matthias Brennwald
Subject: Re: Loading ASCII data files quickly
Date: Mon, 10 Aug 2009 22:42:15 +0200

On Aug 10, 2009, at 6:07 PM, Michael Grossbach wrote:

Matthias Brennwald wrote:
On Aug 10, 2009, at 5:03 PM, Christoph Ellenberger wrote:
I usually use sed to straighten the data and then do the load thing....
something like:

cmd=['sed -n -e "/^ *[0-9]/p" ' fname  ">" Tfname];
if (system(cmd,1))
 error("Fehler 1");
end

xx=load(Tfname);


where fname is the filename and tfname is some temporary filename which I remove afterword with....

cmd=["rm " Tfname];
if (system(cmd,1))
  error("Fehler 4");
end

but this depends on what structure do you want afterward. I sometimes have the coulumnames in the file as well and create a cellarray with the datapoints called Data.X, Data.Y etc. as well.

Hope this helps
Christoph
Ok, but this requires sed to be available. My code needs to work with non-unixy machines, too.

Try reading the header lines using fgetl and the rest of the data with fscanf.
Not tested:
function tdm = tdmread(path2tdmfile)
[fid, msg] = fopen(path2tdmfile, 'r');
if fid < 3, error(msg), endif
first = fgetl(fid);
second = fgetl(fid);
data = fscanf(fid, '%f%f', Inf)
tdm = struct('header', {first; second}, 'data', data);
fclose(fid);

HTH, Michael

This does the trick, thanks. The only thing I needed to add was to reshape the 'data' variable to 2 columns (the above yields a one- column variable).

Thanks
Matthias

----
Matthias Brennwald, Käferholzstrasse 173, CH-8046 Zürich, +41 44 364 17 03




reply via email to

[Prev in Thread] Current Thread [Next in Thread]