Convert 10 minute average to hourly

I have some data recorded at 10 minute interval and would like to calculate the hourly average. Some data is filtered out so using reshape is not applicable.
I could write a code to use for and if logicals but I have a lot of data and it would be to "heavy".
For each data I have the value and time (year, month, day, hour, minute (10,20 etc).
Is there a quicker way than using a long for and if code?

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 5 Juil 2013
Madd = randi([10 20],50,1);
data = [datenum(2013,2,1,0,cumsum(Madd),0), randi(2500,numel(Madd),1)];
% Let your data - two columns -> [date, value]
date1 = datevec(data(:,1));
[a,~,c] = unique(date1(:,1:4),'rows');
out = [a,zeros(size(a,1),2),accumarray(c,data(:,2),[],@mean)];

3 commentaires

sks
sks le 5 Juil 2013
You sir are a gentleman and a scholar. Is it possible to have fun a action/function which is assigned by me. Example instead of finding the mean of the same values, use the atan(x^2/(x+3))? where x is is the values of course.
sks
sks le 5 Juil 2013
I figured it out, thanks for the original answer.
accumarray(c,data(:,2),[],@(x)atan(x.^2./(x+3)))

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
dpb le 5 Juil 2013

0 votes

Reinsert the missing points w/ NaN and if have Statistics toolbox use NANMEAN(); otherwise it's not difficult to filter them out for the sums and use the RESHAPE "trick" you mentioned...

2 commentaires

sks
sks le 5 Juil 2013
Thanks for the reply, I had considered this option. However I also have to perform another action with the data where NaN cannot be used (would return NaN). Again I could filter out NaN but then the code becomes robust.
dpb
dpb le 5 Juil 2013
That's ok; the accumarray() solution is better, anyway.
I was waiting to hear how the timestamps were stored. Fortunately for you Andrei just made an assumption and went on... :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by