Readtable is not reading my delimiter and datetime columns correctly
6 views (last 30 days)
Show older comments
I'm trying to read in a csv file with
d = readtable('testCheck.csv');
but Matlab isn't detecting the delimiter correctly. It detects the delimiter as ' ', instead of ','. I then tried the command.
d = readtable('testCheck.csv','Delimiter', ',');
This command formats the file correctly, besides the 5th and 6th column,which are datetimes. It is reading them as strings, but I want them read as datetimes instead. I tried converting those two columns to datetimes, but I'm having trouble because the times include AM and PM.
Is there a way to read in the file with the times read in as datetime or a way to convert the strings of time with AM/PM to a 24 hour format instead?
0 Comments
Answers (1)
Steven Lord
on 18 May 2022
You might want to use the interactive Import Tool to read in your data. This will let you select how the data is delimited / separated, choose which columns get read in, and specify the types and (where appropriate) formats of the data.
If you need to import multiple files with the same format, you can also perform the setup steps manually then generate code that you can run to import the remainder of the files automatically. You can also study the generated code to learn more about the commands and options MATLAB used to import the data.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!