Problem in creating hourtly timestamp (time axe)

조회 수: 1 (최근 30일)
Adnane CHAKIR
Adnane CHAKIR 2018년 9월 25일
댓글: jonas 2018년 9월 25일
Hello I am tring to create a time axis (time vetor) with the following command:
num_date1 = datenum (03/05/2003 00: 00: 00, 'dd / mm / yyyy HH: MM: SS')
num_dateend = datenum (01/01/2018 00: 00: 00, 'dd / mm / yyyy HH: MM: SS')
Mod = datenum ('01 / 01/2000 01:00:00 ',' dd / mm / yyyy HH: MM: SS ') - datenum ('01 / 01/2000 00:00:00', 'dd / mm / yyyy HH: MM: SS ') %Mod=0.041666666627861559391021728515625; %Horaire
num_dateOK = num_date1: Mod: num_dateend
when I display the result (datestr (num_dateOK, 'dd / mm / yyyy HH: MM: SS')) I find that in a certain moment matlab crash, and it give me a not correct axis of time in the following form:
31/12/2017 09:59:59 12/31/2017 10:59:59 31/12/2017 11:59:59 12/31/2017 12:59:59 31/12/2017 13:59:59 31/12/2017 14:59:59 31/12/2017 15:59:59 31/12/2017 16:59:59 31/12/2017 17:59:59 12/31/2017 18:59:59 12/31/2017 7:59:59 31/12/2017 20:59:59 12/31/2017 9:59:59 12/31/2017 22:59:59 31/12/2017 23:59:59
can someone help me please?

답변 (1개)

jonas
jonas 2018년 9월 25일
편집: jonas 2018년 9월 25일
First of all, your code is buggy. There is no way you can execute those lines by copying them to the workspace, so it is impossible to find your error(s).
More importantly, do not use the outdated format where dates are described by doubles. Use datetime instead.
num_date1 = datetime(2003,05,03,00,00,00)
num_dateend = datetime(2018,01,01,00,00,00)
num_dateOK = num_date1:hours(1):num_dateend
Just change the interval (currently set to 1 hour) per your desire.
Note. Would you rather use a string as input when specifying the date, this is not an issue
num_date1 = datetime('03/05/2003 00:00:00','inputformat','dd/MM/yyyy hh:mm:ss')
  댓글 수: 2
Adnane CHAKIR
Adnane CHAKIR 2018년 9월 25일
sorry .. it was my browser that had changed the format of the commands and removed the datenum's quotes.
I solved the problem, by using the variable dt=60/60/24 to determine the interval (1 hour)
num_date1=datenum('03/05/2003 00:00:00','dd/mm/yyyy HH:MM:SS')
num_dateend=datenum('01/01/2018 00:00:00','dd/mm/yyyy HH:MM:SS')
Mod=60/60/24%Horaire
num_dateOK=num_date1:Mod:num_dateend
Thank you jonas
jonas
jonas 2018년 9월 25일
Happy to help! You should still consider using datetime. You are very unlikely to ever go back to datevec if you try ;)

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by