How to create a sequence of datetime for given set of datetime series (with duplicate dates)?

2 views (last 30 days)
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 Comments
Siddharth Bhutiya
Siddharth Bhutiya on 30 May 2021
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
NS
NS on 31 May 2021
Thanks for suggestions but since I mentioned that I am using R2016a which does not have timetable function. Please provide an alternative solution.

Sign in to comment.

Answers (1)

Chunru
Chunru on 30 May 2021
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 Comments

Sign in to comment.

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!