hourly average of multiple column data

1 回表示 (過去 30 日間)
navan
navan 2016 年 5 月 12 日
コメント済み: Guillaume 2016 年 5 月 12 日
I have made a code to calculate hourly average of minute data. But it works only for single column. I have multiple column of concentration data. How can i get the desired answers. pls help.
day1hour=hour(date==1);
day1bc=BC(find(hour(date==1)));
maxday1=max(day1hour);
for i=1:max(day1hour)
ll= find(day1hour==i);
fffff=BC(ll);
mean_BC_hourly1(i,:)=mean(fffff);
end
The input datas are:
day hour Con 1 con2
1 1 10 20
1 1 20 40
1 2 30 60
1 2 40 80
1 3 50 100
1 3 60 120
1 3 70 140
The answer expected:
con1avg con2avg
15 30
35 70
60 120
  2 件のコメント
Guillaume
Guillaume 2016 年 5 月 12 日
Note that none of the find in your code are necessary. They just slow down the processing.
day1bc = BC(hour(date == 1))); %works just as well
Star Strider
Star Strider 2016 年 5 月 12 日

サインインしてコメントする。

回答 (1 件)

Guillaume
Guillaume 2016 年 5 月 12 日
編集済み: Guillaume 2016 年 5 月 12 日
m = [1 1 10 20
1 1 20 40
1 2 30 60
1 2 40 80
1 3 50 100
1 3 60 120
1 3 70 140]
[dayhour, ~, destrow] = unique(m(:, [1, 2]), 'rows');
subs = [repmat(destrow, 2, 1), repelem([1;2], numel(destrow))];
hourlymean = accumarray(subs, reshape(m(:, [3, 4]), [], 1), [], @mean);
array2table([dayhour, hourlymean], 'VariableNames', {'day', 'hour', 'con1avg', 'con2avg'})
Or the new split apply workflow introduced in R2015b
  2 件のコメント
navan
navan 2016 年 5 月 12 日
編集済み: navan 2016 年 5 月 12 日
Wow. Wonderful. Thanks a ton Guillaume. It is what i wanted really. It is a great help. thank you once again :) But if i have around 10 concentration how should i modify the code ?
Guillaume
Guillaume 2016 年 5 月 12 日
colstoaverage = 3:12;
subs = [repmat(destrow, numel(colstoaverage), 1), repelem((1:numel(colstoaverage))', numel(destrow))];
hourlymean = accumarray(subs, reshape(m(:, colstoaverage), [], 1), [], @mean)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by