2

次のようにフォーマットされたデータがあります。

dtau     E_av        variance    N_sims      Time
0.001   0.497951    0.000211625 25      Sun Apr  3 18:18:12 2011

dtau     E_av        variance    N_sims      Time
0.002   0.506784    0.000173414 25      Sun Apr  3 18:18:58 2011

次に、textscan を使用して、3 行ごとに最初の 4 列 (時間以外) を MATLAB に読み込みます。を使用した後fid = fopen('data.text')、基本的にこれをループする必要があります。

results = textscan(fid, '%f %f %f %f', 1,'headerlines',1);

何か案は?乾杯!

4

2 に答える 2

2
fid = fopen('data.text')
while ~feof(fid)
  results = textscan(fid, '%f %f %f %f', 1,'headerlines',1);
  //Processing...

  for i = 1:2
    fgets(fid)
  end
end

fgets行の終わりまで読み取り、その行のテキストを返します。そのため、2 回呼び出して 2 行をスキップします (関数の戻り値を破棄します)。

于 2011-04-03T17:27:08.273 に答える
0

5 つの列ラベル (文字列) の後に 4 つの数値と 5 つの文字列 (例: 'Sun''Apr''3''18:18:12'および'2011') が続くことがわかっているので、実際にはすべての数値データを単一の N 行 4 列の行列に読み取ることができます。TEXTSCANへの1回の呼び出し:

fid = fopen('data.text','r');                    %# Open the file
results = textscan(fid,[repmat(' %*s',1,5) ...   %# Read 5 strings, ignoring them
                        '%f %f %f %f' ...        %# Read 4 numeric values
                        repmat(' %*s',1,5)],...  %# Read 5 strings, ignoring them
                   'Whitespace',' \b\t\n\r',...  %# Add \n and \r as whitespace
                   'CollectOutput',true);        %# Collect numeric values
fclose(fid);                                     %# Close the file
results = results{1};                            %# Remove contents of cell array
于 2011-04-04T14:49:23.137 に答える