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

1 回表示 (過去 30 日間)
Jon
Jon 2015 年 9 月 21 日
編集済み: Jon 2015 年 9 月 21 日
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 Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by