MATLAB: How to average time at every 5 intervals in matlab

matlab functiontime

Here is my data
02-Sep-2015 09:58:32: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:32: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:33: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3100E-05,5, 2.0000E-02
02-Sep-2015 09:58:34: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
02-Sep-2015 09:58:35: 0, 7.3200E-05,5, 2.0000E-02
I have written some code
n=5;
A=arrayfun(@(i) mean(data(i:i+n-1)),1:n:length(numdata1)-n+1)';
But i find NaN as the output
can i have some suggestions

Best Answer

Starting with your character array:
datastrcell = cellstr(data);
dataparts = regexp(regexprep(datastrcell, {': (\d),', ':(\d\d),'},{':0$1,','.$1,'}),',','split');
dataparts = vertcat(dataparts{:});
timeentries = datenum(dataparts(:,1));
otherentries = str2double(dataparts(:,2:end));
data_as_num = [timeentries(:), otherentries];
Now you can apply your averaging to data_as_num. I do not code it here because I am not sure if you want to average by discrete blocks or by sliding window, and I am not sure what you want to have happen to partial blocks.
Once you have the result, call it avg_as_num, then if you want to convert it back to string format, such as
avg_data_as_str = num2str(avg_as_num(:,2:end), '%.4e,%d,%.4e');
temp_date_as_str = datestr(avg_as_num(:,1), 'dd-mmm-yyyy HH:MM:SS.fff'));
date_as_str = char( regexprep( cellstr(temp_date_as_str), {'\.0(\d)\d', '\.(\d\d)\d'}, {': $1',':$1'}) );
avg_as_str = [date_as_str, avg_data_as_str];
I have assumed here that the ": 0' is short form for ':00' and is intended to mean '.00'. I have also assumed here that it is important to restore the ": 0" form on output for the cases where the tenths of a second is 0. I also assumed that it was important that two digits of time be output. I did not, however, assume that the fractions of a second is always 0, so if there is a fraction of a second which has a non-zero tenth of a second then I leave it there but convert the '.' to ':', such as ':25' instead of '.250'.
Programs sure are less complicated when the data is in a standard format like using '.' for fractions of a second rather than ':'...