Prev: Read data from txt
Next: Writting overloaded function
From: Jan Simon on 6 Aug 2010 09:50 Dear Dustin, > For some reason datenum is rounding to the day precision, where i need precision at the second level. > > dateAR = {'8/4/2010', '8/4/2010 1:00:00 AM'} > datenum(dateAR) > ans = > 734354 > 734354 Obviously the first date is used to determine the format in DATENUM. So you could care for the first string to have the full format. A good idea would be to append ' 00:00:00 AM' to all short date strings: shortIndex = cellfun('length', dateAR) < 11; dateAR(shortIndex) = strcat(dateAR(shortIndex), {' 00:00:00 AM'}); Please note the leading space. NOTE: Calling STRCAT with all inputs are cell strings is faster than calling it with mixed strings and cell strings. DATENUM is remarkably faster, if you specify the date format: datenum(dateAR, 'dd/mm/yyyy HH:MM:SS PM'); Kind regards, Jan
From: Dustin on 6 Aug 2010 11:18 > Dear Dustin, > > > For some reason datenum is rounding to the day precision, where i need precision at the second level. > > > > dateAR = {'8/4/2010', '8/4/2010 1:00:00 AM'} > > datenum(dateAR) > > ans = > > 734354 > > 734354 > > Obviously the first date is used to determine the format in DATENUM. Obvious as it may be I did not know this. > So you could care for the first string to have the full format. A good idea would be to append ' 00:00:00 AM' to all short date strings: > shortIndex = cellfun('length', dateAR) < 11; > dateAR(shortIndex) = strcat(dateAR(shortIndex), {' 00:00:00 AM'}); > Please note the leading space. > NOTE: Calling STRCAT with all inputs are cell strings is faster than calling it with mixed strings and cell strings. > > DATENUM is remarkably faster, if you specify the date format: > datenum(dateAR, 'dd/mm/yyyy HH:MM:SS PM'); This was the first thing I tried, but recieved an error message. I think it was due to the mixed fromat of the dates. But your solution solves my problem. THANK YOU!
From: Jan Simon on 6 Aug 2010 15:24 Dear Dustin, > > > dateAR = {'8/4/2010', '8/4/2010 1:00:00 AM'} > > > datenum(dateAR) > > > ans = > > > 734354 > > > 734354 > > Obviously the first date is used to determine the format in DATENUM. > Obvious as it may be I did not know this. It is hard to fill the necessary tone in the word "obviously". I wanted to insert a short, small, ironical grinning. At least "help datenum" of Matlab 2009a (improved in 2010a?) does not tell anything about this behaviour, and the applied method should not be "obvious", but exactly described in the documentation. So "obvious" is a kind of "damn good hidden". Even reading the source of DATENUM will not reveal immediately, what's going on, because the date functions have been grown to an intelligent parsing platform. I really expect, that Matlab 2010b accepts requests like: datenum('Birthday of my nephew') perhaps with defining the pivot name "Stefan". Kind regards, Jan
From: Dustin on 11 Aug 2010 16:45
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i3hngk$7a9$1(a)fred.mathworks.com>... > Dear Dustin, > > > > > dateAR = {'8/4/2010', '8/4/2010 1:00:00 AM'} > > > > datenum(dateAR) > > > > ans = > > > > 734354 > > > > 734354 > > > > Obviously the first date is used to determine the format in DATENUM. > > > Obvious as it may be I did not know this. > > It is hard to fill the necessary tone in the word "obviously". I wanted to insert a short, small, ironical grinning. At least "help datenum" of Matlab 2009a (improved in 2010a?) does not tell anything about this behaviour, and the applied method should not be "obvious", but exactly described in the documentation. So "obvious" is a kind of "damn good hidden". It's ok I wasn't offended, just commenting. I didn't see anything about it in the 2010a help either. > > Even reading the source of DATENUM will not reveal immediately, what's going on, because the date functions have been grown to an intelligent parsing platform. I really expect, that Matlab 2010b accepts requests like: > datenum('Birthday of my nephew') > perhaps with defining the pivot name "Stefan". > > Kind regards, Jan |