Home > chronux_1_50 > spikesort > datetime2ind.m

datetime2ind

PURPOSE ^

DATETIME2IND Converts date/time lists to serial time indices.

SYNOPSIS ^

function timeinds = datetime2ind(datelist, timelist)

DESCRIPTION ^

DATETIME2IND      Converts date/time lists to serial time indices.
   TIMEINDS = DATETIME2IND(DATELIST, TIMELIST) takes two N x 1 cell
   arrays containing the dates and times (as strings) to be converted
   and returns an N x 1 vector of (double) time indices as described by
   'datenum'.

   The DATELIST entries must be of the format 'mmddyy' and the TIMELIST
   entries 'hhmm'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function timeinds = datetime2ind(datelist, timelist)
0002 %DATETIME2IND      Converts date/time lists to serial time indices.
0003 %   TIMEINDS = DATETIME2IND(DATELIST, TIMELIST) takes two N x 1 cell
0004 %   arrays containing the dates and times (as strings) to be converted
0005 %   and returns an N x 1 vector of (double) time indices as described by
0006 %   'datenum'.
0007 %
0008 %   The DATELIST entries must be of the format 'mmddyy' and the TIMELIST
0009 %   entries 'hhmm'.
0010 
0011 % Argument checking.
0012 if ((nargin < 2) || (length(datelist) ~= length(timelist)) || ...
0013     (~iscell(datelist)) || (~iscell(timelist)))
0014     error('Two cell arrays of equal length are required.');
0015 end
0016 
0017 if (isempty(datelist)),  timeinds = [];  return;   end
0018 
0019 % Make copies of the dates and start times in a more user-friendly numeric matrix.
0020 dateN = str2num(cat(1, datelist{:}));
0021 timeN = str2num(cat(1, timelist{:}));
0022 
0023 % Next, break dates and times into component pieces.
0024 yearnums  = rem(dateN, 100);
0025 monthnums = floor(dateN/10000);
0026 daynums   = rem(floor(dateN/100), 100);
0027 hournums  = floor(timeN/100);
0028 minnums   = rem(timeN, 100);
0029 secnums   = zeros(size(dateN,1), 1);
0030 
0031 % Fix the yearnums (pivot on 2000)
0032 latter = (yearnums <= 50);
0033 yearnums(latter) = yearnums(latter) + 2000;
0034 yearnums(~latter) = yearnums(~latter) + 1900;
0035 
0036 % Use these pieces to compute the unique, sortable serial number for each record
0037 timeinds = datenum(yearnums, monthnums, daynums, hournums, minnums, secnums);

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003