Generate a Definite timestamp sequence

조회 수: 7 (최근 30일)
Stefan Azzopardi
Stefan Azzopardi 2018년 6월 11일
편집: Stefan Azzopardi 2018년 6월 12일
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

답변 (1개)

per isakson
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
Stefan Azzopardi
Stefan Azzopardi 2018년 6월 12일
편집: Stefan Azzopardi 2018년 6월 12일
Hi isakson, thanks for your help, In the meantime I still continued to try out some other solutions and managed to create what I was expected using the below code:
t1 = datetime (2018,03,01,0,0,0)
t2 = datetime (2018,03,31,23,55,00)
Timestamp = t1:minutes(5):t2
Timestamp = Timestamp.'
Now I am trying to integate three tables using outerjoin. Do you know if it is possible to join 3 or more tables using outerjoin? I managed to integrate the new variable 'timestamp' with another table of 2 columns ('Timestamp', 'Variable1') and now I intend to add another 2 columns ('Timestamp', 'Variable2')
Best Regards

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by