how to calculate mean and stdev of unequally intervalled data based on different time?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Andrei Bobrov
2012-10-26
编辑:Andrei Bobrov
2012-10-26
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!