How to skip some lines in a text file?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Theo Score
am 29 Dez. 2018
Kommentiert: Theo Score
am 3 Jan. 2019
Good Day,
I have a dump3000.data file;
ITEM: TIMESTEP
3180000
ITEM: NUMBER OF ATOMS
61728
ITEM: BOX BOUNDS ff pp ff
-0.35 0.35
0 1
-0.35 0.35
ITEM: ATOMS id type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius c_p_touch
6149 1 -0.0115737 0.259234 -0.337672 0 -9 0 -0.0157745 -0.0243613 0.000244609 -0.00332803 -0.0147639 -0.00982034 -2.3864 0.495408 0.52126 0.0075 4
48702 1 -0.0220014 0.269678 -0.339369 0 -7 0 -0.0105548 -0.024631 5.32708e-05 -0.00454286 -0.0176825 0.00459746 3.32294 -1.43248 -0.944346 0.0075 3
6786 1 -0.0309551 0.286898 -0.33882 0 -9 0 -0.00475241 -0.024127 0.00232548 -0.00487091 -0.00637367 -0.00174202 3.06644 -0.852896 -0.95503 0.0075 5
31898 2 -0.01633 0.289193 -0.337365 0 -10 0 -0.00320024 -0.0419555 0.025742 -0.00474243 -0.0310394 0.0122298 19.9952 1.35577 0.761368 0.0075 3
38738 2 -0.00213965 0.293131 -0.339981 0 -11 0 -0.00942052 -0.0363392 0.000276149 -0.0144915 -0.00922721 0.000227933 -3.16269 -0.908586 -1.21652 0.0075 5
I want to skip the first 9 lines of this data and start manipulating the remainder. The piece of code is;
filename = sprintf('%s%d%s','dump',3000,'.data');
Data=importdata(filename);
en=length(Data);
d=zeros(en,1);
counter=0;
for i=1:en
if Data(i,2)<=x1 && Data(i,2)>=x2 && Data(i,3)<=y1 && Data(i,3)>=y2 && Data(i,4)<=z1 && Data(i,4)>=z2
counter=counter+1;
if counter==0
A=zeros(1,5);B=zeros(1,5);C=zeros(1,5);D=zeros(1,5);E=zeros(1,5);
end
end
end
I want Data to be a matric of the "after" 9 lines information so that I can access them as arrays values and start working from there.
Thanks.
0 Kommentare
Akzeptierte Antwort
per isakson
am 29 Dez. 2018
Bearbeitet: per isakson
am 29 Dez. 2018
See textscan in the documentation and try something like
cac = textscan( fid, '%f%f%f%f...', 'Headerlines',9' , 'CollectOutput',true );
num = cac{1};
The format specifier needs one %f per column.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!