Readtable gives unusual results reading data from a text file.
4 次查看(过去 30 天)
显示 更早的评论
I'm trying to read a lot of text files using readtable. All the files have 7 columns of data, although the last column is usually blank.
Readtable normally gives this:
39×7 table
Var1 Var2 Var3 Var4 Var5 Var6 Var7
____ ____ ____ ____ ____ ____ __________
2009 10 6 3 33 29 {0×0 char}
2009 10 6 3 36 12.3 {0×0 char}
2009 10 6 3 36 53.3 {0×0 char}
2009 10 6 3 37 6.5 {0×0 char}
...
But one text file gives a very different result:
7×1 table
x20111118015544_7RF
_________________________
{'2011 11 18 01 33 43.7'}
{'2011 11 18 01 33 51.2'}
{'2011 11 18 01 33 60.0'}
{'2011 11 18 01 35 32.3'}
{'2011 11 18 01 36 03.9'}
{'2011 11 18 01 36 25.2'}
{'2011 11 18 01 36 33.4'}
This file actually has 26 lines, but readtable only returns the last seven lines and somehow takes the table column name from the 19th line. This line has a value that should go into Var7, but so do lines in other files and they don't cause this problem.
I suspect the text file has a bad character in it, but I can't find it.
Any suggestions?
采纳的回答
Stephen23
2022-4-4
T = readtable('20160419-2010.txt','NumHeaderLines',0)
T = readtable('20111118-0021.txt','NumHeaderLines',0)
T = readtable('20080505-0553.txt','NumHeaderLines',0)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!