Merging text data from sequence data files in a folder
显示 更早的评论
Hello, here is my script to merge data into a single file.
files=dir('*.data');
fileout='merged.data';
fout=fopen(fileout,'w');
for cntfiles=1:length(files)
fin=fopen(files(cntfiles).name);
linecount = 0;
while ~feof(fin)
linecount = linecount + 1;
linetext = fgetl(fin);
if linecount >= 10 % Nine (9) header lines being skipped
fprintf(fout, '%s %d\n', linetext, cntfiles);
end
end
fclose(fin);
end
fclose(fout);
Original data structure is like this:
ITEM: TIMESTEP
1000
ITEM: NUMBER OF ATOMS
362
ITEM: BOX BOUNDS mm mm mm
-1.1 1.1
-1.00019 1.9
-0.75007 0.75007
ITEM: ATOMS id type type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius
1 1 1 0.450082 1.76687 -0.101338 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324
2 1 1 -0.0949301 1.76202 -0.0205438 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324
3 1 1 0.0403266 1.78975 0.0742209 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324
The code works well to merge the individual .data files but the resulting merged.data have an extra column at the end (20 column) with the id of the data input. For instance, below is the point of interface of data from two files;
360 1 1 -0.146193 1.86848 0.0697032 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0189 1
361 1 1 -0.265613 1.86954 0.0197866 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0189 1
362 1 1 0.217502 1.7725 0.0649903 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0189 1
1 1 1 0.450082 1.75687 -0.101338 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324 2
2 1 1 -0.0949301 1.75202 -0.0205438 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324 2
3 1 1 0.0403266 1.77975 0.0742209 0 0 0 -0 -1 -0 0 0 0 0 0 0 0.0324 2
Can you kindly help to address this. Thank you.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!