2016-10-18 5 views
0

内の1つのファイルに複数のファイルから、ユニークなタイムスタンプを付けて、私は、次の形式の30個のファイル(データはダミーで、ちょうどフォーマットを参照してください)持っている:私はちょうどすべてのタイムスタンプをしたい、この30個のファイルからMathWorks社のMATLAB

timestamp,id 
1,a 
2,b 
3,a 
1,a 
5,c 
6,b 
3,a 

をすべてのファイルから一意のタイムスタンプを1行に1つのファイルに保存します。 私はPythonで同じコードを書いています。ファイルサイズは500 MB程度です。 私はそれをmatlabに書きたいと思います。

答えて

1

可能な解決策の1つとして、次のコード例を参照してください。私はそれをテストしていませんが、それはあなたの問題を解決するために使用できる関数とアルゴリズムの簡単な概要を与えるでしょう:

% save all your filenames in one struct 
dataFiles = dir('yourFileNamesHere'); 

% if you know how many data lines you are going to read, you should 
% do a preallocation of your data struct `s` here! 

currentDataLine = 1; 

% loop to read all your files 
for i=1:length(dataFiles); 
    fp = fopen(datFiles(i).name); 

    % read the whole file content 
    while(~feof(fp)) 
     % parse the data from one line 
     line = fgetl(fp); 
     % read the data line as two separate strings 
     tempData = textscan(line,'%s','delimiter',','); 

     % store the data 
     s(currentDataLine).timestamp = tempData{1}; 
     s(currentDataLine).data = tempData{2}; 

     currentDataLine = currentDataLine + 1; 

    end; 
    fclose(fp) 
end; 

% when all the data is read you can use the `unique`-function 
% to delete entries with an identical timestamp. 

% finally store your data in one file 
関連する問題