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!