The function textscan is problematic and has serious bug!
古いコメントを表示
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 件)
Walter Roberson
2023 年 9 月 21 日
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 件のコメント
Xiaoqiu
2023 年 9 月 21 日
Walter Roberson
2023 年 9 月 21 日
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
2023 年 9 月 21 日
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
2023 年 9 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!