フィルターのクリア

Reading data files from a directory/folder and rearranging the data

1 回表示 (過去 30 日間)
Theo Score
Theo Score 2017 年 1 月 16 日
回答済み: Walter Roberson 2017 年 1 月 16 日
Hi All,
I have a folder named "Results" in my c drive (C:/Results). In the folder, there are data files named data1, data2, data3,...,data(n) (data files can go upto a couple of thousands). A sample of such a data files is given below;
TIMESTEP
2000
NUMBER OF ATOMS
552
BOX BOUNDS ff ff ff
-0.15 0.15
-0.5 0.35
-0.15 0.15
id type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius
25 1 -0.0545632 0.192913 -0.0474573 0 0 0 0 -1.15554 0 0 -0.00532977 0 0 0 0 0.0034
168 1 -0.0202324 0.192866 -0.0469896 0 0 0 0 -1.15593 0 0 -0.00532977 0 0 0 0 0.0034
182 1 -0.0298158 0.193937 -0.0364063 0 0 0 0 -1.14681 0 0 -0.00532977 0 0 0 0 0.0034
444 2 0.0202324 0.192866 -0.0469896 0 0 0 0 -1.15593 0 0 -0.00532977 0 0 0 0 0.0034
458 2 0.0298158 0.193937 -0.0364063 0 0 0 0 -1.14681 0 0 -0.00532977 0 0 0 0 0.0034
301 2 0.0545632 0.192913 -0.0474573 0 0 0 0 -1.15554 0 0 -0.00532977 0 0 0 0 0.0034
46 1 -0.0558349 0.209037 -0.0450717 0 0 0 0 -1.00937 0 0 -0.00532977 0 0 0 0 0.0034
146 1 -0.0615904 0.205083 -0.03638 0 0 0 0 -1.04714 0 0 -0.00532977 0 0 0 0 0.0034
152 1 -0.0508907 0.203654 -0.0355757 0 0 0 0 -1.06038 0 0 -0.00532977 0 0 0 0 0.0034
273 1 -0.0602642 0.213358 -0.0393904 0 0 0 0 -1 0 0 0 0 0 0 0 0.0034
For a single data file, I managed to write a script that skips the first 9 lines and only returns the data, and the script is;
fid = fopen('data1.txt','r');
S = textscan(fid,'%f','delimiter','\n','HeaderLines',9);
fclose(fid);
data = reshape(S{1},18,[])';
The output is well and good. I currently need some help to extend the code so that I can read all the data files in the folder "Results" and arrange the results based on the first entry on the first column "id". The data is dumped in the files randomly and thus the need to identify the "id" and the associated results.
I look forward to your help. Thank you.

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 16 日

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by