フィルターのクリア

read headerlines from a text file

6 ビュー (過去 30 日間)
Liqing
Liqing 2011 年 4 月 28 日
I am trying to read each parameters in the second headerline of the file:
This is my code:
File =['data3.txt'];
fid = fopen(File,'rt');
tmp = textscan(fid, repmat('%s',1,9), 1, 'delimiter','', 'headerlines',1);
meta = tmp{1};
fclose(fid);
The problem is that the string I got is a whole string with everything connected together. Is there a way I can get these parameters separately?
The spaces between two adjacent parameters could differ from file to file.
Thank you.

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 4 月 28 日
File =['data3.txt'];
fid = fopen(File,'rt');
tmp = textscan(fid, repmat('%s',1,9), 1, 'headerlines',1);
meta = tmp{1};
fclose(fid);
>> [tmp{:}]'
ans =
'3'
'90G10'
'B90G10*2*1'
'11JUL90'
'1836'
'29'
'10.9'
'94'
'37.1'
  1 件のコメント
Liqing
Liqing 2011 年 4 月 28 日
Thank you very much. It works. Sorry about the confusion.

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

その他の回答 (3 件)

Walter Roberson
Walter Roberson 2011 年 4 月 28 日
Leave out the 'delimiter',''

Liqing
Liqing 2011 年 4 月 28 日
Thank you very much for the reply.
Unfortunately, that does not work. Once I remove the delimiter, what I got is only the first string - '3'.

Fangjun Jiang
Fangjun Jiang 2011 年 4 月 28 日
What do you mean "that does not work". Type this:
[tmp{:}]'

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by