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 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