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
average every 4 points in a dataset
Posted: Jul 25, 2013 2:58 AM

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.

This is a learning phase so I can run something similar later for larger data sets.
I have got the following so far from help here:

on my program
x = 1:16;
data = [660.770000000000
483.450000000000
445.320000000000
659
380.250000000000
509.930000000000
439.920000000000
454.600000000000
527.750000000000
537.300000000000
543.920000000000
1024.59000000000
727.480000000000
704.420000000000
796.520000000000
588.650000000000];

% Get the running average in a moving 4x1 window.
averaged_data = conv(data, ones(4,1)/4);
% 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?

anything can help
Thanks a lot

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