How can i sum every 12th block of data from a large data set?

I have a set of data for energy performance sampled every 5 minutes. I would like to condense the energy outputs into hourly totals - hence blocks of 12.
I have imported the data into a variable array from Excel, called 'unit1'. the data i want lies in column 9:
>> y=(unit1(1:124390,9));
As one can see it is a large data set.
All i know so far is that i can pick out every 12th value:
>> y=(unit1(1:12:124390,9));
but that's as far as i have got - some others have done resampling but it is not clear.
In Brief - lots of data, tell the sum of every block of 12 in a continous fashion.
I then hope to produce a frequency distribution of the energy output over a period of one year (or 8760 hours)

댓글 수: 2

124390 is not a multiple of 12. What do you plan on doing with the incomplete hours? Do the first 12 data points belong to one hour, or do they span two hour bins?
James
James 2013년 4월 17일
편집: James 2013년 4월 17일
I kept it simple for the question - i will use only the first complete years number of values (24x365 = 8760) so after calculating the block-sums of 12 in an new array, plot only the first 8760. the first 12 points do cover one hour. incomplete hours will be at the end and ignored.

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

 채택된 답변

Cedric
Cedric 2013년 4월 17일
You can go for a solution around:
n = size(unit1, 1) ; % Should be 124390,
id = zeros(n, 1) ; % Build vector of ids:
id(1:12:n) = 1 ; % 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 ...
id = cumsum(id) ;
sumHour = accumarray(id, unit1(:,9)) ;

댓글 수: 2

Thats brilliant - thank you very much.
I need to sum variable by months so I get monthly sums:
Year=randn(1,365);
months365=[31 28 31 30 31 30 31 31 30 31 30 31];
any help is appreciated.
thanks

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 4월 17일
Here it is for data that is a multiple of 12 long:
% Create sample data a multiple of 12 long.
unit1 = rand(124392, 9);
% Exact column #9.
column9 = unit1(:,9);
% Reshape it into a 10366 row by 12 column matrix.
reshapedColumn9 = reshape(column9, [length(column9)/12, 12]);
% Get the means going cross columns.
theMeans = mean(reshapedColumn9, 2);
% These are the means of blocks of 12 in the original matrix.
Of course someone will pack that all into a single line but I made it explicitly in several lines and put in comments so that you can follow the thought process more easily.

댓글 수: 1

I'm voting for this solution; I proposed ACCUMARRAY before the OP wrote the comment indicating that he would truncate the data to a multiple of 12, and CUMSUM/ACCUMARRAY were a solution for managing situations where the "multiple of 12" condition is not necessary.

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

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

태그

질문:

2013년 4월 17일

댓글:

2019년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by