calculating hourly means of a matrix

조회 수: 2 (최근 30일)
Richard
Richard 2012년 8월 26일
댓글: Venkata 2017년 5월 11일
I have a dataset in the following format:
dd = datenum('2009-04-17 02:00');
ddend = datenum('2009-11-24 12:27');
Day = dd:(1./24./60):ddend;
time = datevec(Day);
data = rand(length(time),12);
Where time refers to the time (in minutely intervals) and data refers to a matrix of data points. I would like to find the best possible way of calculating the hourly means of each column of the matrix (i.e. mean of every 24 rows in each individual column). How would I achieve this, by taking into consideration the time variable?

채택된 답변

Jan
Jan 2012년 8월 27일
limit = floor(length(time) / 60) * 60;
data_hour = reshape(data(1:limit), 60, []);
data_mean = mean(data_hour, 1);

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 8월 27일
other variant
[c,c,c] = unique(time(:,1:4),'rows');
s{2} = kron((1:size(data,2))',ones(size(data,1),1));
s{1} = kron(ones(size(data,2),1),c);
result = accumarray(s,data(:),[],@mean);
  댓글 수: 1
Venkata
Venkata 2017년 5월 11일
Dear Andrei Bobrov,
Could you please elaborate on your code. I want to reshape hourly mean data which is in vector form to a matrix, but there might be some data (hourly values) missing. When I tried your code, I got an error related to array size. Mine is a large array with 210888 rows.
Thank you.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by