how to calculate mean and stdev of unequally intervalled data based on different time?

Hello every one,
I am trying to calculate the hourly mean and standard deviation of my five minutes data. The number of data should be 12 in one hour but unfortunately due to data missing sometimes less than 12 and even only one data.
My data format in the file is as follows (two consecutive data set):
7/16/2012 6:40 2.20E+03
7/16/2012 6:45 1.87E+03
7/16/2012 6:50 1.83E+03
7/16/2012 6:55 1.94E+03
7/16/2012 7:00 1.86E+03
7/16/2012 7:05 1.74E+03
7/16/2012 7:10 1.78E+03
7/16/2012 7:15 1.65E+03
7/16/2012 7:20 1.77E+03
7/16/2012 7:25 1.74E+03
7/16/2012 7:30 1.82E+03
7/16/2012 7:35 1.65E+03
7/16/2012 8:40 1.68E+03
7/16/2012 8:45 1.61E+03
7/16/2012 8:50 1.78E+03
7/16/2012 8:55 1.67E+03
7/16/2012 9:00 1.66E+03
7/16/2012 9:05 1.66E+03
7/16/2012 9:10 1.71E+03
7/16/2012 9:15 1.65E+03
7/16/2012 9:20 1.73E+03
7/16/2012 9:25 1.66E+03
7/16/2012 9:30 1.70E+03
7/16/2012 9:35 1.64E+03
After calculating the mean and stdev, I want to get the output in a new array as follows:
start-time End-time Mean stdev
I will highly appreciate any of your helping hand. Thank you very much in advance.
Rahman

Respuestas (2)

Matt J
Matt J el 26 de Oct. de 2012
Editada: Matt J el 26 de Oct. de 2012
Use HISTC to bin the data into hourly intervals.
Then use ACCUMARRAY to get the mean and std over each bin.
Andrei Bobrov
Andrei Bobrov el 26 de Oct. de 2012
Editada: Andrei Bobrov el 26 de Oct. de 2012
Your data in file yourtext.txt:
7/16/2012 6:40 2.20E+03
7/16/2012 6:45 1.87E+03
7/16/2012 6:50 1.83E+03
7/16/2012 6:55 1.94E+03
7/16/2012 7:00 1.86E+03
7/16/2012 7:05 1.74E+03
7/16/2012 7:10 1.78E+03
7/16/2012 7:15 1.65E+03
7/16/2012 7:20 1.77E+03
7/16/2012 7:25 1.74E+03
7/16/2012 7:30 1.82E+03
7/16/2012 7:35 1.65E+03
7/16/2012 8:40 1.68E+03
7/16/2012 8:45 1.61E+03
7/16/2012 8:50 1.78E+03
7/16/2012 8:55 1.67E+03
7/16/2012 9:00 1.66E+03
7/16/2012 9:05 1.66E+03
7/16/2012 9:10 1.71E+03
7/16/2012 9:15 1.65E+03
7/16/2012 9:20 1.73E+03
7/16/2012 9:25 1.66E+03
7/16/2012 9:30 1.70E+03
7/16/2012 9:35 1.64E+03
f1 = fopen('yourtxt.txt'); c = textscan(f1,'%s %s %f'); fclose(f1);
[Y M D H] = datevec(strrep(strcat(c{1},'_',c{2}),'_',' '));
[a,cc,cc] = unique([Y M D H],'rows');
a1 = num2cell(a,1);
daten = cellstr(datestr(datenum(a1{1:3},a1{4}+1,0, 0)));
data = ...
cell2mat(cellfun(@(x)[mean(x),std(x)],accumarray(cc,c{3},[],@(x){x}),'un',0));
out = [daten, num2cell(data)];
ADD
f1 = fopen('yourtxt.txt'); c = textscan(f1,'%s %s %f'); fclose(f1);
sdate = strrep(strcat(c{1},'_',c{2}),'_',' ');
[~,~,~, H MM] = datevec(sdate);
t = abs(diff([H MM]*[1;1/60]) - 5/60) > eps(100);
dc = accumarray(cumsum([1;t]),c{3},[],@(x){x});
datan = num2cell(cell2mat(cellfun(@(x) [mean(x), std(x)],dc,'un',0)));
ii = find(t);
out = [sdate([1;ii]) sdate([ii+1;end]) datan];

3 comentarios

Dear Andrei,
Thank you very much for your kind afford. In the time stamp the last digit is the minute which is 5 minutes interval. In fact, I want to get the mean and stdev of this five minute data and want to step to the next mean and stdev when the time difference is more than five minutes as you can see in between lines 12 and 13. So, from this data I suppose get two mean and stdev. the ouput should be as follows:
start end mean stdev
7/16/2012 6:40 7/16/2012 7:35 m1 s1
7/16/2012 8:40 7/16/2012 9:35 m2 s2
Thank you once again for you afford.
Rahman
Dear Andrei,
Thank you very much for the ADD.

Iniciar sesión para comentar.

Preguntada:

el 26 de Oct. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by