Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
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

Réponses (2)

Matt J
Matt J le 26 Oct 2012
Modifié(e) : Matt J le 26 Oct 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 le 26 Oct 2012
Modifié(e) : Andrei Bobrov le 26 Oct 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 commentaires
Md. Moklesur Rahman
Md. Moklesur Rahman le 26 Oct 2012
Dear Andrei,
Thank you very much for the ADD.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time Series dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by