Hello, I have a Log.txt file with data;
ITEM: TIMESTEP1000ITEM: NUMBER OF ATOMS113ITEM: BOX BOUNDS mm mm mm-1.1 1.1-1.00019 1.9-0.75007 0.75007id type x y z1 1 0.450082 1.76687 -0.1013382 1 -0.0949301 1.76202 -0.02054383 1 0.0403266 1.78975 0.07422094 1 0.195614 1.75958 0.01069065 1 0.227547 1.84632 -0.0987141 1 0.144155 1.76642 0.1089742 1 0.288044 1.85155 0.03872143 1 0.370195 1.81785 -0.100844 1 0.383223 1.78207 0.03870855 1 -0.285847 1.72996 -0.002400171 1 0.450142 1.77285 0.1179992 1 -0.318942 1.74455 -0.06515673 1 -0.198368 1.76376 0.07883634 1 0.255091 1.74895 0.03696465 1 -0.128421 1.72431 -0.1138981 1 0.486869 1.83805 0.02398842 1 0.0405222 1.80871 -0.109443 1 -0.359026 1.75984 -0.000664154 1 -0.436089 1.73765 -0.06887595 1 -0.15772 1.81532 -0.0857257
I wrote a code as given below to skip the first 8 lines and subsequently read the entire text and in the process leaving non-numbers.
fid = fopen('Log.txt','r');%Advance 8 lines:
linesToSkip = 8;for ii = 1:linesToSkip-1 fgetl(fid);end%Process all remaining lines
tline = fgetl(fid);To_Excel_Data = []; %You should allocate if you know how large your data is
while ~feof(fid) tline = fgetl(fid); %Getting rid of non-numbers
tline = regexprep(tline,'[^0-9\s+-.eE]',''); To_Excel_Data = [To_Excel_Data; str2num(tline)];endfclose(fid);
The Output of the code is;
1 1 0.450082 1.76687 -0.1013382 1 -0.0949301 1.76202 -0.02054383 1 0.0403266 1.78975 0.07422094 1 0.195614 1.75958 0.01069065 1 0.227547 1.84632 -0.0987141 1 0.144155 1.76642 0.1089742 1 0.288044 1.85155 0.03872143 1 0.370195 1.81785 -0.100844 1 0.383223 1.78207 0.03870855 1 -0.285847 1.72996 -0.002400171 1 0.450142 1.77285 0.1179992 1 -0.318942 1.74455 -0.06515673 1 -0.198368 1.76376 0.07883634 1 0.255091 1.74895 0.03696465 1 -0.128421 1.72431 -0.1138981 1 0.486869 1.83805 0.02398842 1 0.0405222 1.80871 -0.109443 1 -0.359026 1.75984 -0.000664154 1 -0.436089 1.73765 -0.06887595 1 -0.15772 1.81532 -0.0857257
Which is well and good. Now I am looking for help to extent the code with textscan (or an alternative) so that I can filter and group the data according to the identity of the first element in column 1 so that the output is;
1 1 0.450082 1.76687 -0.1013381 1 0.144155 1.76642 0.1089741 1 0.450142 1.77285 0.1179991 1 0.486869 1.83805 0.0239884 2 1 -0.0949301 1.76202 -0.02054382 1 0.288044 1.85155 0.03872142 1 -0.318942 1.74455 -0.06515672 1 0.0405222 1.80871 -0.10944 3 1 0.0403266 1.78975 0.07422093 1 0.370195 1.81785 -0.100843 1 -0.198368 1.76376 0.07883633 1 -0.359026 1.75984 -0.00066415 4 1 0.195614 1.75958 0.01069064 1 0.383223 1.78207 0.03870854 1 0.255091 1.74895 0.03696464 1 -0.436089 1.73765 -0.0688759 5 1 0.227547 1.84632 -0.0987145 1 -0.285847 1.72996 -0.002400175 1 -0.128421 1.72431 -0.1138985 1 -0.15772 1.81532 -0.0857257
I look forward to your help. Thank you.
Best Answer