Readtable Delimiters on two similar files gives differing result
Show older comments
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 Comments
Stephen23
on 12 Jun 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
on 12 Jun 2024
Jason
on 12 Jun 2024
Eric Sofen
on 17 Jun 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.
Accepted Answer
More Answers (1)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
