For completeness, this is the other csv file that was read properly. Both have underscores, so matlab shouldn't be splitting the columns based on '_' as a separator. I am very confused!
"ReadTable" column reading error/bug?
35 次查看(过去 30 天)
显示 更早的评论
Hello,
I am attempting to read this csv file with the 'readTable' function, and when I do the columns of the original csv file are not read into matlab correctly. Instead, they are jumbled up, and some columns appear when they never existed in the original csv file (see attached csv file). I have tried this with another csv file created from the same program, and it works without issue.
filepath = '/Users/Nick/Desktop/SLO/CellProfiler/3kDa_PC3_P19_5x/Attept2Pipeline_Perinuclear_Ring';
T = readtable(filepath);
I get the warning "column headers were modified" but even if I were to do:
readtable(filepath,,'ReadVariableNames',false)
(or read variable names, true) I still get the same exact column mess up.
Is there something I am doing wrong here?
Thank you for your time!
采纳的回答
Stephen23
2022-3-4
编辑:Stephen23
2022-3-4
Simpler and more efficient:
T = readtable('Attept2Pipeline_Perinuclear_Ring.csv', 'Delimiter',',')
T = readtable('Attept2Pipeline_Perinuclear_Ring_SuccessfulRead.csv', 'Delimiter',',')
4 个评论
Stephen23
2022-3-4
编辑:Stephen23
2022-3-4
"I find it odd that it read two similar csv files differently..."
It is not very odd: READTABLE (and family) parses the file text and performs a whole lot of analysis of the file content to automagically determine things like the delimiter character, the field types, etc. etc. How do you think it knows that the first column is numeric? How does it even know what constitutes the first column?
This file parsing works in many cases, but of course any algorithm can get confused. The more the file deviates from a basic format with "standard" characters, the more likely it is that the file parsing will algorithm will need some hints to work correctly, which is exactly why this exists too:
I suspect that the filenames (in the CSV files) are the problem: they contain many underscores, whitespace, and periods which are just primed to confuse poor READTABLE's algorithm.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!