Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: average every 4 points in a dataset
Replies: 2   Last Post: Jul 25, 2013 5:09 AM

 Messages: [ Previous | Next ]
 Isabel Posts: 1 Registered: 7/25/13
Re: average every 4 points in a dataset
Posted: Jul 25, 2013 5:09 AM

Thanks a lot!

averaged every 4 points is what i wanted. so the option below is great.

mean(reshape(data,4,4),1

just a question what 'valid' is doing in this context

averaged_data = conv(data, ones(4,1)/4,'valid')

it actually worked as well for the conv option. so it gave me an output of 13 point vector in which the 4 average points appeared from row 1 to 13.

562.135
492.005
498.625
497.275
446.175
483.05
489.8925
515.8925
658.39
708.3225
750.1025
813.2525
704.2675

thanks!

"Nasser M. Abbasi" wrote in message <ksqjor\$r9v\$1@speranza.aioe.org>...
> On 7/25/2013 1:58 AM, Isabel wrote:
> > Hi - this is begginers question.
> > I have a data set - 1 vector of 16 points - I would like to average every 4 points and plot them
> >and also save them.
> >

>
> You want the average of each 4 points, or a running average with a window of size=4?
>
> You are doing a running average below, which is not the same as what you
> started saying.
>

> > % Get the running average in a moving 4x1 window.
>
> Ok, so it is a running average then?
>

> > averaged_data = conv(data, ones(4,1)/4);
>
> try
>
> averaged_data = conv(data, ones(4,1)/4,'valid')
>

> > % Take the middle, because the convolution is longer -
> >this was a suggestion from someone, I am not sure why and what this line does.
> > averaged_data = averaged_data(2:17);
> > % Plot everything.
> > plot(x, data, 'r');
> > hold on;
> > plot(x, averaged_data, 'b', 'LineWidth', 3);
> >
> > % Just take every third one in case he wanted that.
> > xs = 1:4:16;
> > averaged_data_subsampled = averaged_data(1:4:end);
> > plot(xs, averaged_data_subsampled, 'g+', 'LineWidth', 3, 'markersize',
> > 28);
> >
> > this should work, however by looking at the averages
> >
> > averaged_data_subsampled it gives the following values
> > 286.055000000000 - point 1 --- inconrrect
> > 498.625000000000 - point 2
> > 489.892500000000 - point 3
> > 750.102500000000 - point 4
> >
> > These averages are correct for point 4, 3, and 2. what is
> >going on with the first point? also from 16 data points the programs is leaving
> >the first 2 and the last 2 lines out. why?
> >

>
> I do not understand what is it you really looking for, is it
> the running average or just the average of each 4 points segments.
>
> But try the 'valid' option to conv and see if that what you want.
> There are 'full' and 'same' also. Each handles the window differently.
>
> If you just want the mean of each 4 values then simply write
>
> mean(reshape(data,4,4),1)
>

> > anything can help
> > Thanks a lot
> >

>
> --Nasser

Date Subject Author
7/25/13 Isabel
7/25/13 Nasser Abbasi
7/25/13 Isabel