Generate a Definite timestamp sequence
8 ビュー (過去 30 日間)
古いコメントを表示
How can I generate a column with a timestamp showing day-month-year hh:mm:ss for every 5 mins of a month? For example I need to create a column for every 5mins of March, therefore the table should show like this:
01/03/2018 00:00:00
01/03/2018 00:05:00
01/03/2018 00:10:00 until
31/03/2018 23:55:00
0 件のコメント
回答 (1 件)
per isakson
2018 年 6 月 12 日
編集済み: per isakson
2018 年 6 月 12 日
The old way
>> vec = repmat([2018,3,1,0,0,0], 31*24*12, 1 );
>> minutes = ( 0 : 5 : 5*(31*24*12-1) )';
>> vec(:,5) = minutes;
>> sdn = datenum( vec );
>> str = datestr( sdn, 'dd/mm/yyyy HH:MM:SS' );
>> str(1:4,:)
ans =
4×19 char array
'01/03/2018 00:00:00'
'01/03/2018 00:05:00'
'01/03/2018 00:10:00'
'01/03/2018 00:15:00'
>> str(end,:)
ans =
'31/03/2018 23:55:00'
However, I guess this is not exactly what you want.
The new way (Introduced in R2014b)
>> t = datetime( vec );
>> t(1)
ans =
datetime
01-Mar-2018 00:00:00
>> t(end)
ans =
datetime
31-Mar-2018 23:55:00
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!