필터 지우기
필터 지우기

hourly average of multiple column data

조회 수: 1 (최근 30일)
navan
navan 2016년 5월 12일
댓글: Star Strider 2016년 5월 13일
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 (BC) data. I want hourly average of multiple columns How can i get the desired answers. pls help.
day1bc=BC(find((date==1)));
day1hour=hour(date==1);
maxday1=max(day1hour);
for i=1:maxday1
HI= find(day1hour==i);
Bcv=day1bc(HI);
mean_BC_hourly1(i,:)=mean(Bcv);
end
The input datas are:
day hour BC BC;
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:
BC BC;
15 30;
35 70;
60 120;

채택된 답변

Star Strider
Star Strider 2016년 5월 12일
Use accumarray for the hours, although you would have to loop over the days:
% day hour BC BC
Mtx = [ 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;];
% ‘for’ % LOOP OVER DAYS
out(:,1) = accumarray(Mtx(:,2), Mtx(:,3), [], @mean);
out(:,2) = accumarray(Mtx(:,2), Mtx(:,4), [], @mean);
% ‘end’ % LOOP OVER DAYS
In the loop over days, replace the ‘:’ in the ‘out’ array reference with the day number.
  댓글 수: 4
navan
navan 2016년 5월 13일
Dear Star Strider Thanks again. It helped me so much. Thank you for your precious time ,effort and great help
Star Strider
Star Strider 2016년 5월 13일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by