From: Remco Benthem de Grave on
I'm trying to read a .txt file with headers, using textscan. This works fine for some files, but in some it only reads the first line of data.

My code:

fid = fopen([name,'_taskdata','.txt'], 'r');
readdata = textscan(fid, '%f %f %f %f %f %f %f %f %f %f\n', 'headerlines', 4);
taskinfo = cell2mat(readdata); %data name defined

An part of the file of which only the first row is read:

s002
14042010
TASK INFORMATION - RE65_24V motor, HEDS5400 encoder, Maxon 20A Amplifier
task nr result req.succ. episode end angle start (s) end (s) eps. host req.suc.host rel.start(s)
2.000000 1.000000 20.000000 0.000000 27.035444 70.890228 71.277405 0.000000 20.000000 -0.118697
3.000000 0.000000 19.000000 0.000000 29.655884 75.463272 75.892082 0.000000 19.000000 -0.169669
4.000000 5.000000 19.000000 0.000000 30.457964 79.982536 80.443146 0.000000 19.000000 -0.120718


A part of the file that works:

subject: 002
date: 15-01-2010
TASK INFORMATION - RE65_24V motor, HEDS5400 encoder, Maxon 20A Amplifier
task nr result req.succ. episode end angle start (s) end (s) rel.start(s) FFOn? duration(s)
1.000000 1.000000 0.000000 0.000000 24.479997 7.136000 7.529000 7.529000 0.000000 0.393000
2.000000 1.000000 0.000000 0.000000 27.900000 12.086000 12.480000 12.480000 0.000000 0.394000
3.000000 1.000000 0.000000 0.000000 30.240000 16.350000 16.838000 16.838000 0.000000 0.488000
4.000000 1.000000 0.000000 0.000000 32.400002 20.992000 21.482000 21.482000 0.000000 0.490000
5.000000 1.000000 0.000000 0.000000 30.420000 25.411000 25.876000 25.876000 0.000000 0.465000



I don't really see the difference that could explain my problem.

I would be very thankful for any suggestions.

Thanks
Remco
From: dpb on
Remco Benthem de Grave wrote:
> I'm trying to read a .txt file with headers, using textscan. This works
> fine for some files, but in some it only reads the first line of data.
> My code:
>
> fid = fopen([name,'_taskdata','.txt'], 'r');
> readdata = textscan(fid, '%f %f %f %f %f %f %f %f %f %f\n', 'headerlines', 4);
> taskinfo = cell2mat(readdata); %data name defined

....

> I don't really see the difference that could explain my problem.
> I would be very thankful for any suggestions.

I'd start by looking at the files w/ a hex viewer and see if there's
something embedded differently at the newline or other non-printing
characters or somesuch. One wouldn't think, but...

Also, I'm not positive w/ testing otomh since it's been a while since I
fiddled w/ one of these exercises, but since you're reading all values
on a line I don't think you need the newline in the format; textscan()
will, I think, just keep on truckin' until EOF.

I'd guess there's where the problem lies--somewhere it's getting
confused on those altho just _why_ I don't know w/o looking at
originals--perhaps a difference in the the system platforms between who
wrote and who's reading them.

One thing I see that's somewhat interesting/puzzling is it seems there
are 11 column headers but only 10 values?

--