How to create a sequence of datetime for given set of datetime series (with duplicate dates)?
2 次查看(过去 30 天)
显示 更早的评论
I have table with a column DATETIME of the format ''dd-MM-yyyy HH:mm:ss'' (shown below) and wish to create a sequence of datetime series from 09:30 to 17:00 for each datetime mentioned in column. I have duplicate dates e.g. two datetime in column are "06-01-2010 13:40:00" and "06-01-2010 15:10:00". And i need the separate sequence for each of them.
Please help me on that and I have matlab R2016a version only.
DATETIME
'05-01-2010 15:05:00'
'06-01-2010 13:40:00'
'06-01-2010 15:10:00'
'07-01-2010 16:10:00'
'07-01-2010 16:40:00'
'08-01-2010 13:30:00'
'08-01-2010 13:40:00'
'08-01-2010 13:50:00'
'11-01-2010 16:10:00'
'11-01-2010 16:40:00'
'12-01-2010 16:15:00'
'12-01-2010 16:40:00'
'12-01-2010 16:55:00'
'13-01-2010 14:10:00'
'13-01-2010 15:20:00'
'13-01-2010 16:25:00'
'14-01-2010 15:50:00'
'14-01-2010 16:20:00'
'14-01-2010 16:30:00'
'14-01-2010 16:40:00'
2 个评论
Siddharth Bhutiya
2021-5-30
Since you are working with timestamped data timetable would be a better datatype over table. You could convert your table into a timetable first using table2timetable function. After that you can easily achieve this using something like retime
回答(1 个)
Chunru
2021-5-30
You can use the following code to find the row index of the required time.
dstr =[...
'05-01-2010 15:05:00'
'06-01-2010 13:40:00'
'06-01-2010 15:10:00'
'07-01-2010 16:10:00'
'07-01-2010 16:40:00'
'08-01-2010 13:30:00'
'08-01-2010 13:40:00'
'08-01-2010 13:50:00'
'11-01-2010 16:10:00'
'11-01-2010 16:40:00'
'12-01-2010 16:15:00'
'12-01-2010 16:40:00'
'12-01-2010 16:55:00'
'13-01-2010 14:10:00'
'13-01-2010 15:20:00'
'13-01-2010 16:25:00'
'14-01-2010 15:50:00'
'14-01-2010 16:20:00'
'14-01-2010 16:30:00'
'14-01-2010 16:40:00'];
dn = datetime(dstr, 'InputFormat', 'dd-MM-yyyy HH:mm:SS');
[hh, mm, ss] = hms(dn);
idx = datetime(2010, 1, 1, hh, mm, ss) >= datetime(2010, 1, 1, 09, 30, 0) ...
& datetime(2010, 1, 1, hh, mm, ss) <= datetime(2010, 1, 1, 17, 00, 0);
dstr(idx, :)
If your data matrix is arranged in a similar way with dstr. Then you can extract your data:
x = data(idx, :); % assume that you have many columns of data.
4 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!