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

2 次查看(过去 30 天)
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.

采纳的回答

Jon
Jon 2015-9-21
编辑:Jon 2015-9-21
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by