Trying to Average Data sets

37 views (last 30 days)
R.L.P.
R.L.P. on 30 Sep 2012
Hi all - I have two data sets I am trying to average and am a new MATLAB user. The first is 1 column with 14 rows and I want to every two data points to end with 1 column with 13 rows. Example = [1 2 3 4 ...] and final = [1.5 2.5 3.5. ...]
The second is a large data set with N columns and 75000+ rows. I would like to average this set by every 50th point to reduce down to N columns and 1500 rows.
I would appreciate any help ... I have been able to go nowhere with this. Thank you, RLP

Answers (3)

Matt J
Matt J on 30 Sep 2012
Edited: Matt J on 30 Sep 2012
Using your first example:
>> A=(1:14).';
>> result= interp1(A,(1.5:13.5).')
result =
1.5
2.5
3.5
4.5
5.5
6.5
7.5
8.5
9.5
10.5
11.5
12.5
13.5
The second case would work much the same. See "help interp1".
  1 Comment
R.L.P.
R.L.P. on 30 Sep 2012
Thanks Matt, but will this work if the intervals are not evenly spaced. I used example of equally spaced, but data sets are not.

Sign in to comment.


Image Analyst
Image Analyst on 30 Sep 2012
You want to try something a little more advanced than the intuitive brute force looping method? Try blockproc:
clc;
clearvars;
array2D = rand(75000, 5);
tic;
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:));
blockSize = [50 1];
blockMeanArray = blockproc(array2D, blockSize, meanFilterFunction);
[rows columns] = size(blockMeanArray)
toc
  9 Comments
R.L.P.
R.L.P. on 3 Oct 2012
Average every 50 values is what I am looking for ... sorry for the confusion. I wasn't clear enough in my question
Image Analyst
Image Analyst on 4 Oct 2012
That's what my blockproc demo above does. The usual way most people would do it is to extract a column at a time, and then reshape that column into a 2D matrix with 50 columns and then average across the columns. Then repeat for all of the other 4 columns. 6 of one, half a dozen of the other.

Sign in to comment.


Andrei Bobrov
Andrei Bobrov on 30 Sep 2012
Edited: Andrei Bobrov on 1 Oct 2012
[ii ii] = ndgrid(ones(50,1),(1:1500)');
[i1 i2] = ndgrid(ii(:),1:N);
out = accumarray([i1(:) i2(:)],yourmatrix(:),[],@mean);
other variant
ii = ndgrid((1:1500)',ones(50,1));
[i1 i2] = ndgrid(ii(:),1:N);
out = accumarray([i1(:) i2(:)],yourmatrix(:),[],@mean);
  2 Comments
R.L.P.
R.L.P. on 30 Sep 2012
What is 'N' in this example?
Andrei Bobrov
Andrei Bobrov on 30 Sep 2012
Edited: Andrei Bobrov on 30 Sep 2012
The initial array yourmatrix with size (75000 x N).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!