フィルターのクリア

How to use textscan from the middle of a file.

2 ビュー (過去 30 日間)
Fredrik
Fredrik 2011 年 11 月 23 日
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!
  1 件のコメント
Fredrik
Fredrik 2011 年 11 月 23 日
Should be new row after HL) after [EOH] and [BOD]..

サインインしてコメントする。

採用された回答

Andrei Bobrov
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);
  2 件のコメント
Fredrik
Fredrik 2011 年 11 月 23 日
That seems to help. I did though lie a little bit. The rows before my start is always 29 and some of them have more letters than just [EOH], forexample one line is" Data field 11,17,23,29,35,41,47,53,59,65,71,77,83,89,95,101,107,113,119,125,131,137,143,149,155,161,167,173,185,191: Quality(S/N*10)(LL to HL)"
So for some reason, not all the text before my actual data is removed...
Fredrik
Fredrik 2011 年 11 月 23 日
I managed to fix it. Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by