Not expected results using datevec funcion

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 件のコメント

Luis Fernando
Luis Fernando 2014 年 1 月 18 日
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.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 18 日
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! :-)
Jan
Jan 2014 年 1 月 18 日
Instead of the slow and complicated cellfun method to join strings, strcat is niocer and faster:
dd = strcat(d, ' 00:00:00')
Luis Fernando
Luis Fernando 2014 年 1 月 18 日
Jan,
Good hint as well! Thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Objects についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by