Readtable Delimiters on two similar files gives differing result
Mostrar comentarios más antiguos
Is there any reason why using Readtable to open the following 2 csv files produces different results

Im using readtable as it has the ability to auto detect how many lines to skip, and generally works well - except for the case above and I can't see why. My aim is to get the real data into a uitable
try
[file,folder]=uigetfile({'*.csv';'*.xls'},'Open Image',app.startfolder);
catch
[file,folder]=uigetfile({'*.csv';'*.xls'},'Open Image','C:\');
end
fullpath=fullfile(folder,file);
app.startfolder=folder;
T = readtable(fullpath,MissingRule="omitrow",Delimiter=","); %Delimiter="tab"
app.UITable.Data=table2array(T);
This is what I am seeing:

I have tried omitting the Delimiter option in readtable, but with no luck
(Note my header files can be different which is why I want to try and avoid skipping " a known number of " rows.)
4 comentarios
Stephen23
el 12 de Jun. de 2024
"Is there any reason why using Readtable to open the following 2 csv files produces different results"
Yes: because there is no such thing as an infallible algorithm. The more your file deviates from an actual comma-separated-values file, the more likely that READTABLE's automagical algorithm will struggle. This is always true: no matter what heuristic algorithm is implemented, there will always be (edge)cases that will confound and confuse it.
The more help you give READTABLE to guide it when importing the more likely it is to import the data you expect.
Jason
el 12 de Jun. de 2024
Jason
el 12 de Jun. de 2024
Eric Sofen
el 17 de Jun. de 2024
If the header structure is consistent between files, the NumHeaderLines argument in readtable, will help to start parsing the CSV from the right line and not get tripped up by the commas in the date line.
Respuesta aceptada
Más respuestas (1)
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

