Read tab spaced data e.g. textscan not working...

1 visualización (últimos 30 días)
Jon
Jon el 21 de Sept. de 2015
Editada: Jon el 21 de Sept. de 2015
Hello,
I have this data but it won't read properly... I can go into every text file and delete the header but for hundreds of files, I would prefer to write a code that reads it correctly. There are three headerlines which I would like to discard, followed by three columns of numbers which I would like to store into arrays or a matrix.
Tue Sep 08 13:35:32 2015
Number of Points = 33801
Depth (nm) Load (µN) Time (s)
1.891960 168.877011 0.000000
1.724944 170.487155 0.001000
1.427851 166.373680 0.002000
0.464998 163.441419 0.003000
0.547294 159.472315 0.004000
0.690833 160.371511 0.005000
0.285518 164.715072 0.006000
-0.199364 162.450703 0.007000
-0.818151 163.764859 0.008000
.....
Any help would be much appreciated. Thanks.

Respuesta aceptada

Jon
Jon el 21 de Sept. de 2015
Editada: Jon el 21 de Sept. de 2015
Nevermind, I got it to work now.
%
fileID = fopen('testy.txt');
C = textscan(fileID,'%*s%*s%*s%*s%*s\n%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s');
d = textscan(fileID,'%n%n%n','delimiter','\t','headerlines',1,'treatAsEmpty', {'MAX'})
for some reason it needed " 'treatAsEmpty', {'MAX'} ". However, I'm not quite sure why it needed C and for d, the headerlines is 1 instead of 3.

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by