Input Files
The attached file1.txt and file2.txt have identical structure (9 lines of header followed by data arranged in 15 columns). The header looks like this:
ITEM: BOX BOUNDS pp pp pp
-9.6850194863609573e-01 1.0509150710611115e+02
-8.0199580669506787e-01 8.7024035559953262e+01
-2.0781435615505643e+02 2.0781435615505643e+02
ITEM: ATOMS mass id type x y z c_1 c_2 f_eco[1] f_eco[2] c_sv[1] c_sv[2] c_sv[3] c_sv[4] backforth
Expected Behavior
I want to extract the numerical data in the header contained on lines 6-8 (3 rows and 2 columns). I use readmatrix to do this as follows (for file1.txt.):
simcell = readmatrix('file1.txt','Filetype','text','Range',[6 1 8 2])
simcell =
-0.9646 105.0876
-0.7987 87.0208
-207.7989 207.7989
It also works to extract the data that appears after the header as follows:
data_raw = readmatrix('file1.txt','FileType','text','NumHeaderLines',9);
I have hundreds of thousands of files like this, and this approach works for almost all of them, but occasionally it fails...
Unexpected Behavior
When I do the same thing for file2.txt, it returns NaNs and I can't figure out why:
simcell = readmatrix('file2.txt','Filetype','text','Range',[6 1 8 2])
In an effort to debug the issue I looked at hidden characters, delimiters, character encoding and all appear identical between the two input files. However, I did find that if I manually delete all of the data after the header (attached as file2short.txt) I get the correct result:
simcell = readmatrix('file2short.txt','Filetype','text','Range',[6 1 8 2])
simcell =
-0.9685 105.0915
-0.8020 87.0240
-207.8144 207.8144
Question
I know there are many other ways one could accomplish the desired result, but that is not my question. My question is: why does this unexpected behavior occur in this example?