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?
64 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nicholas Scott
el 4 de Mzo. de 2022
Comentada: Nicholas Scott
el 4 de Mzo. de 2022
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!
Respuesta aceptada
Stephen23
el 4 de Mzo. de 2022
Editada: Stephen23
el 4 de Mzo. de 2022
Simpler and more efficient:
T = readtable('Attept2Pipeline_Perinuclear_Ring.csv', 'Delimiter',',')
T = readtable('Attept2Pipeline_Perinuclear_Ring_SuccessfulRead.csv', 'Delimiter',',')
4 comentarios
Stephen23
el 4 de Mzo. de 2022
Editada: Stephen23
el 4 de Mzo. de 2022
"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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!