I have a very long vector of date strings (1000000+) in Matlab that I want to convert to a serial number format. The issue is that not every date string is the same format. They are one of two formats,
'2010-03-04 12:00:00.1'
or
'2010-03-04 12:00:00'
The problem is that not all the strings have the millisecond precision. There is no regular pattern as to where these strings without milliseconds occur. The data is originally read from a data file, and the strings currently exist as cell arrays. My work around this is as 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 a better way to go about this? It is important that I retain the millisecond precision when it is present. The intent of this is that I will have to extract and calculate statistics on data associated with each time based on different time criteria, and I figured it would be easier if the dates were handled as numbers.