The problem is due to errors in the sliceBad.txt file, like these on line 391:
0.2848764-119 0.1045924-120 0.1045924-120 0.2848764-119 -0.6596584-109
Notice: There are no "E"s.
So when you textscan(__,'%f',5) this line
result = textscan(' 0.2848764-119 0.1045924-120 0.1045924-120 0.2848764-119 -0.6596584-109','%f',5)
result{:}
ans =
0.2849
-119.0000
0.1046
-120.0000
0.1046
You get 5 numbers, but they are not what was supposed to be written there. Notice you miss the rest of the numbers on the line beyond the first 5; they are not counted.
On the other hand, when doing textscan(__,'%f',1) to read the numbers one-at-a-time, and you encounter a problematic line like this in the file, you'd count 10 numbers.
Whatever program created these files messes up and omits the "E" when the exponent takes up more than two digits, it appears.
This explains all the behavior you observe:
- When you textscan each line, specifying to read 5 floating-point numbers each time, your counts from the good file and the bad file are the same because you are failing to read the rest of the numbers on lines where this missing "E" problem happens.
- When you textscan one floating-point number from the file at a time, you get some extra counts from the bad file because of this missing "E" problem.