How to use textscan from the middle of a file.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi. I am not very used to textscan and I really do not understand the help text. I have a textfile with A lot of text before the actuall data starts: " HL) [EOH] [BOD] 20111006 0:00,1210,134,98,984,7.83,235,2.47," etcetra with more columns. 20111006 0:10,1209,135,98,989,5.83,234,6.47," is next row and so on.
How can I with textscan only get the time in the beginning and remove all text before data starts, and remove all data after the time.
Any suggestions?
Thank you!
채택된 답변
Andrei Bobrov
2011년 11월 23일
[EDIT]
for the case when nameyourfile.txt contains data in the form:
'20111006 0:00,1210,134,98,984,7.83,235,2.47'
'20111006 0:10,1209,135,98,989,5.83,234,6.47'
fid = fopen('w3.txt');
d = textscan(fid,'%8s %5s %*s');
fclose(fid);
out0 = [d{:}];
t = cellfun(@(x)strcmp(x(end),','),out0(:,2));
out0(t,2) = cellfun(@(x)['0' x(1:end-1)],out0(t,2),'un',0);
out = arrayfun(@(x)[out0{x,:}],(1:size(out0,1))','un',0);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!