Reputation: 3990
How would I import the data from the fourth row from the following .dat file:
#0 Date-time: 07/06/2011 09:13:53
#1 Recorder: 10T2607
#2 File type: 1
#3 Columns: 3
#4 Channels: 1
#5 Field separation: 0
#6 Decimal point: 0
#7 Date def.: 0 0
#8 Time def.: 0
#9 Channel 1: Temperature(°C) Temp(°C) 3 1
#11 Reconvertion: 0
#19 Line color: 1 2 3 4
#30 Trend Type Number: 1
#33 Limit Temp. Corr. OTCR: 0
1 07.04.11 08:00:00 17,433
2 07.04.11 08:05:00 17,446
3 07.04.11 08:10:00 17,458
4 07.04.11 08:15:00 17,458
So, following the line that begins with #33 I would like to import 17,433 (which should be 17.433) then 17,446 and so on. I have tried to use textscan and headerlines by specifying that the data begins on line 13:
filename = 'Folder\data.dat');
fid = fopen(filename);
data = textscan(fid,'%f\t%f\t%f\t%f\n','Headerlines',13);
fclose(fid);
However, this does not work (in the sense that MATLAB returns an empty array). I guess this is due to the second and third column not being a floating point number, however, it does not work when I specify it to be a string either. What should I try next?
Upvotes: 0
Views: 2523
Reputation: 9317
First, note that you have 14 headerlines.
For the data import, you can try the following:
filename = 'Folder\data.dat';
fid = fopen(filename);
data = textscan(fid,'%f\t%s\t%s\t%s','Headerlines',14);
a = cellfun(@(x) str2num(strrep(x, ',', '.')), data{4});
fclose(fid);
This results in
a =
17.4330
17.4460
17.4580
17.4580
Upvotes: 1