フィルターのクリア

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

2 ビュー (過去 30 日間)
NS
NS 2021 年 5 月 30 日
コメント済み: Chunru 2021 年 6 月 1 日
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
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
NS
NS 2021 年 5 月 31 日
Thanks for suggestions but since I mentioned that I am using R2016a which does not have timetable function. Please provide an alternative solution.

サインインしてコメントする。

回答 (1 件)

Chunru
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 件のコメント
NS
NS 2021 年 5 月 31 日
Please provide any help on this with R2016a.
Chunru
Chunru 2021 年 6 月 1 日
Can you provide your data as a table in that case?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by