DATESTR2NUM - Fast conversion of DATESTR to DATENUM
The builtin DATENUM command is very powerful, but if the input is known to be valid and formatted exactly, a specific MEX can be much faster:
For single strings DateStr2Num takes <1% of the processing time of DATENUM (even with specified date format), for a {1 x 10000} cell string, DateStr2Num needs 0.17% to 2.7% of the DATENUM time. (Matlab 2009a, MSVC 2008 using SSE2 optimization).
D = DateStr2Num(S, F)
INPUT:
S: String or cell string in DATESTR(F) format.
In opposite to DATENUM the validity of the input string is *not* checked,
e.g. if month is in [1:12] and hour in [0:23].
F: Integer number defining the input format. Accepted:
0: 'dd-mmm-yyyy HH:MM:SS' 01-Mar-2000 15:45:17
1: 'dd-mmm-yyyy' 01-Mar-2000
29: 'yyyy-mm-dd' 2000-03-01
30: 'yyyymmddTHHMMSS' 20000301T154517
31: 'yyyy-mm-dd HH:MM:SS' 2000-03-01 15:45:17
300: 'yyyymmddTHHMMSS.FFF'
OUTPUT:
D: Serial date number.
EXAMPLE:
C = {'2010-06-29 21:59:13', '2010-06-29 21:59:13'};
D = DateStr2Num(C, 31)
>> [734318.916122685, 734318.916122685]
Equivalent Matlab command (but a column vector is replied ever):
D = datenum(C, 'yyyy-mm-dd HH:MM:SS')
Precompiled Mex files: http://www.n-simon.de/mex
Tested: Matlab 6.5, 7.7, 7.8, 32bit, WinXP
Compiler: LCC 2.4/3.8, BCC 5.5, Open Watcom 1.8, MSVC 2008
Compatibility to MacOS, Linux, 64 bit is assumed, but not tested.
See also: DateConvert (Jan Simon)
http://www.mathworks.com/matlabcentral/fileexchange/25594 |