Discussion:
Load data from ascii files
(too old to reply)
cuachua
2010-01-19 13:13:03 UTC
Permalink
Hi every body,

I would like to read data from many ascii files (*.asc) that content header (100 lines) and the different number of data lines. Following is example of 2 data lines:

12:35:16;?;?;2;1;2;-61.86;10.67;3535499943.759124;5000000;512;2;-65.03;9.51;3446499743.795071;5000000;512;?;?;?;?;?;?;?
12:35:17;9.394587;53.196232;2;1;2;-61.86;10.67;3535499943.759124;5000000;512;2;-64.11;10.99;3446499743.795071;5000000;512;?;?;?;?;?;?;?

where "?" is NaN. In each line, needed datas are seperated by ";"

I want to load all these data to save to .mat file. Anybody of you has the experience on doing the same thing? please help me.

Thank you very much,
TK
Leslie McBrayer
2010-01-19 13:53:05 UTC
Permalink
Post by cuachua
I would like to read data from many ascii files (*.asc) that content
header (100 lines) and the different number of data lines. Following is
12:35:16;?;?;2;1;2;-61.86;10.67;3535499943.759124;5000000;512;2;-65.03;9.51;3446499743.795071;5000000;512;?;?;?;?;?;?;?
12:35:17;9.394587;53.196232;2;1;2;-61.86;10.67;3535499943.759124;5000000;512;2;-64.11;10.99;3446499743.795071;5000000;512;?;?;?;?;?;?;?
where "?" is NaN. In each line, needed datas are seperated by ";"
I want to load all these data to save to .mat file.
For your data, assuming that every row has the same number of fields (24 in
the two sample lines), I would use textscan. Read the first column (which
seems to be a time) as a string (%s); the rest are numbers (%f).

So, for example:

% Set up a format string to read a string and 23 numbers
% on each line of the file.
formatstr = ['%s' repmat('%f', 1, 23)];

% Read the file.
fid = fopen('myfile.asc');
mydata = textscan(fid, formatstr, 'HeaderLines', 100, 'Delimiter', ';',
'TreatAsEmpty', '?');
fclose(fid);
cuachua
2010-01-19 16:37:04 UTC
Permalink
thank you very much indeed!

Loading...