Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Theo Score
Theo Score am 16 Jan. 2017
Beantwortet: Walter Roberson am 16 Jan. 2017
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.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Jan. 2017

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by