Problems reading datetimes with readtable
3 次查看(过去 30 天)
显示 更早的评论
I have a bunch of text files with dates and times.
Some of them are like this (there is a space at the end of each line):
2022-12-18 00:59:24
2022-12-18 01:00:54
And some of them are like this (no space at the end):
2022-12-28 02:09:16 t
2022-12-28 03:59:56 t2
I want to end up with two arrays, whichever type of file I read. An array of datetimes and an array of strings, empty for the first type of file.
When I read the files using readtable, the first type of file returns an array of datetimes.
Reading the second type of file returns three arrays, an array of datetimes with only the dates, an array of durations and an array of the strings. When I try and add the durations to the datetimes, I get only the dates. Like this:
Is there a better approach? If not, why can't I add the duration to the datetime.
2 个评论
the cyclist
2022-12-29
Can you upload some of the data instead of just describing it? You can use the paper clip icon in the INSERT section of the toolbar.
采纳的回答
Jeremy Hughes
2022-12-29
There is a slight issue with the file format in question. The second case looks to readtable like three columns if you choose space as a delimiter, so separating the "Datetime" from the "t" column isn't possible. If the file looked like:
2022-12-28 02:09:16, t
2022-12-28 03:59:56, t2
Then you wouldn't have the same issue as the datetime is separate from the other data.
With space as delimiter, I expect you to get a datetime, then a duration, then a string, and you can add durations to datetimes to get a new datetime array.
T.Date + T.Time
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!