Read csv with quotes and datetime stamp (readtable configuration)
Show older comments
Hi,
I have a csv file which contains the following format for each line. I understand how fscanf can be used for parsing data if the first digit is just a number: https://www.mathworks.com/matlabcentral/answers/1805220-read-csv-with-quotes-and-numbers. I tried setting this up for a datetime entry in the first field. However this gets tricky as I have to scan individual fields in the date and time if using fscanf.
Is there a more efficient way to parse and scan this using readtable where I can use the datatime variable format so that the date and time can be directly included in the post processing of the data?
Unfortunately I am not able to remove the quotes at this time due to the way in which the datafile is generated. Thanks a lot !
Data format:
14-Sep-2022 10:02:38.140000,"1034,19,AB"
14-Sep-2022 10:02:38.140000,"1034,19,AB"
Accepted Answer
More Answers (1)
dpb
on 14 Sep 2022
1 vote
readtable will import the file time field as a datetime variable automagically; you don't need to do anything except read it.
You'll then have to split the second column that will be imported as a cellstr array
I thought could add the " to the 'Whitespace' but that didn't work by itself -- would take a fair amount of effort to modify an import options object to account for the additional variables; think it's simpler to just import as is and split. Or, of course, you could read the file as text and delete the " and rewrite or parse from memory instead.
1 Comment
Categories
Find more on Dates and Time 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!