Dear colleagues,
I am writing from Brazil in order to get some help about datavec funciton.
I am using this fucntion to convert a date string data to vector format ([yy mm dd HH MM SS])
In Brazil date format is defined as follows: dd/mm/yy. I have a set of date data in two main formats. one without timestamp and another with timestamp, for instance: '13/12/2013' , '13/12/2013 00:15:00', respectively.
I get an error when I call the function to get the conversion:
Situation 1) result = datevec('13/12/2013', 'dd/mm/yyyy HH:MM:SS');
When I use the function with data with timestamp, as follows
Situation 2) result = datevec('13/12/2013 00:00:00', 'dd/mm/yyyy HH:MM:SS');
or
Situation 3) result = datevec('13/12/2013 00:15:00', 'dd/mm/yyyy HH:MM:SS');
I get correct answer:
Anybody has some hint to handle situation 1?
I appreciate any help. Thanks all in advance.
Best regards, Luis.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 17일
편집: Azzi Abdelmalek 2014년 1월 17일

1 개 추천

Use this
result = datevec(datestr('13/12/2013', 'dd/mm/yyyy HH:MM:SS'))
datestr will set the missed time to 00:00:00

댓글 수: 5

Azzi, thank you for your rapid reply.
However, the command you have recommended results " >> result = datevec(datestr('13/12/2013', 'dd/mm/yyyy HH:MM:SS'))
result =
19 5 6 0 0 0
>> "
an answer that not match with the expected result: [2013 12 13 0 0 0] which is the desired answer.
Anyway, I thank you again for your atention. See ya, mate.
Try this
d={'13/12/2013','26/12/2013 19:20:05'}
dd=cellfun(@(x) [x ' 00:00:00'],d,'un',0)
out=datevec(dd,'dd/mm/yyyy HH:MM:SS')
Luis Fernando
Luis Fernando 2014년 1월 18일
Azzi, it works as a charm! Thank you for your help, my friend. It is gonna help a lot! Have a good night or day! :-)
Instead of the slow and complicated cellfun method to join strings, strcat is niocer and faster:
dd = strcat(d, ' 00:00:00')
Jan,
Good hint as well! Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품

태그

질문:

2014년 1월 17일

댓글:

2014년 1월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by