Dealing with date strings with different formats in Matlab -


i have long vector of date strings (1000000+) in matlab want convert serial number format. issue not every date string same format. 1 of 2 formats,

'2010-03-04 12:00:00.1'

or

'2010-03-04 12:00:00'

the problem not strings have millisecond precision. there no regular pattern these strings without milliseconds occur. data read data file, , strings exist cell arrays. work around follows:

for i=1:length(dates),     if length(dates{i})==19         dates(i)=datenum(temp);     elseif length(dates{i})==21         dates(i)=datenum(temp,'yyyy-mm-dd hh:mm:ss.fff');     end end 

is there perhaps better way go this? important retain millisecond precision when present. intent of have extract , calculate statistics on data associated each time based on different time criteria, , figured easier if dates handled numbers.

in matlab r2010b, i'm able desired output when calling datenum no additional formatting arguments:

>> datestrs = {'2010-03-04 12:00:00.1'; ...  %# sample strings                '2010-03-04 12:00:00'}; >> datenum(datestrs)  ans =    1.0e+005 *      7.3420            %# same? no, command window isn't displaying      7.3420            %#   many places after decimal point.  >> format long        %# let's make show more decimal places >> datenum(datestrs)  ans =    1.0e+005 *     7.342015000011574  %# , there's difference!    7.342015000000000 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -