Prev: XBEE with matalb
Next: ADX, +DI, -DI, parabolic SAR
From: Richard Wylde on 23 Jun 2010 06:02 Hi there, I'm somewhat new to matlab (and in general, programming) and therefore require some help. I have a data set of temperatures over a 5 minute interval. I wish to average these temperatures over a 30 minute interval instead. I therefore know that I need to add up each 6 entries, and then divide by 6. I need to repeat this process every 6 entries until I have completed the process for the entire data set. Once this is done, I then want to put the new averaged data into a new array. For example, say I have the following (representing 60 minutes of data): 1 2 6 2 1 4 6 2 6 8 5 2 I wish to turn it into the following: 2.6 4.8 How would I go about this? Any help would be hugely appreciated. Richard.
From: us on 23 Jun 2010 06:11 "Richard Wylde" <rwylde(a)gmail.com> wrote in message <hvsm2u$p35$1(a)fred.mathworks.com>... > Hi there, > > I'm somewhat new to matlab (and in general, programming) and therefore require some help. > > > I have a data set of temperatures over a 5 minute interval. I wish to average these temperatures over a 30 minute interval instead. I therefore know that I need to add up each 6 entries, and then divide by 6. I need to repeat this process every 6 entries until I have completed the process for the entire data set. Once this is done, I then want to put the new averaged data into a new array. > > For example, say I have the following (representing 60 minutes of data): > > 1 > 2 > 6 > 2 > 1 > 4 > 6 > 2 > 6 > 8 > 5 > 2 > > I wish to turn it into the following: > > 2.6 > 4.8 > > > > How would I go about this? Any help would be hugely appreciated. > > Richard. one of the solutions v=[1 2 6 2 1 4 6 2 6 8 5 2].'; r=mean(reshape(v,[],2)) % r = 2.6667 4.8333 us
From: Oleg Komarov on 23 Jun 2010 06:14 "Richard Wylde" <rwylde(a)gmail.com> wrote in message <hvsm2u$p35$1(a)fred.mathworks.com>... > Hi there, > > I'm somewhat new to matlab (and in general, programming) and therefore require some help. > > > I have a data set of temperatures over a 5 minute interval. I wish to average these temperatures over a 30 minute interval instead. I therefore know that I need to add up each 6 entries, and then divide by 6. I need to repeat this process every 6 entries until I have completed the process for the entire data set. Once this is done, I then want to put the new averaged data into a new array. > > For example, say I have the following (representing 60 minutes of data): > > 1 > 2 > 6 > 2 > 1 > 4 > 6 > 2 > 6 > 8 > 5 > 2 > > I wish to turn it into the following: > > 2.6 > 4.8 > > > > How would I go about this? Any help would be hugely appreciated. temp = [1 2 6 2 1 4 6 2 6 8 5 2]; mean(reshape(temp, 6,[])) this solution works only if rem(numel(temp),6) == 0, that is if the number of elements is divisible by 6 with no remainder. If it is not just add up som Nan at the end and instead of mean, use nanmean (Stats TB) Oleg
From: Richard Wylde on 23 Jun 2010 06:30 Thanks for both of the answers, that worked perfectly. I appreciate the speed of the replies. Richard.
From: ImageAnalyst on 23 Jun 2010 07:06
Richard: An alternative method that you may find handy sometime is blockproc(). With that you can also use a much more complicated function than a simple average. |