The function textscan is problematic and has serious bug!
Afficher commentaires plus anciens
The function textscan is really problematic and it gives me a huge lot of troubles, especially for my nerves!
I updated two text files (which are sliceGood.txt and sliceBad.txt). They contains the same number of figures(which is 16512) and stores the figures in the same fashion.
Then I have two matlab scripts(counterGoodAndBadSlice.m and compaireGoodBadLineByLine.m). They counter the number of figures in two text files by 2 different two algorithms.
For short, I will call them counter and comparire. Both two algorithms involves the use of textscan function:
- For counter, it use textscan to read the float figures one by one till the end of file.
- For compaire, it reads a line one time and use textscan to identify the float figures in one line and carries on this procedue till the end of file.
Two script yields the different result: the counter script indicates sliceGood.txt has 16512 figures and sliceBad.txt has 16544 figures. But the compaire script indicates that both two text files have the same number of figures: 16512.
If I am not wrong, this is a big bug for textscan. Please the stuff verifies this problem and response to me!
1 commentaire
Xiaoqiu
le 22 Sep 2023
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 21 Sep 2023
You coded
if totalNumFigureBad == totalNumFigureGood
disp('The textscan is problematic!');
end
and
if counterBad == counterGood
disp('The textscan is problematic!');
end
but if the counts are equal then textscan is NOT problematic: it would be problematic if the counts were NOT equal.
5 commentaires
Xiaoqiu
le 21 Sep 2023
Walter Roberson
le 21 Sep 2023
I am seeing differences in the counts for counterGoodAndBadSlice that I cannot account for as yet.
I modified that code to read the files line by line, and to use textscan() to read all of the values on the line. When I do that, so far it thinks the files have the same number of values.
Walter Roberson
le 21 Sep 2023
Line 378 of sliceBad.txt has
0.2073446E-99 -0.6596584-109 -0.4864104-110 -0.4864104-110 -0.6596584-109
Notice that has no 'E' character between the -0.6596584 and the -109 . All of the exponents in the file that are more than 100 are missing their 'E' character.
Not a bug in textscan() -- bug in your file.
countagain2()
Xiaoqiu
le 22 Sep 2023
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!