Trying to Average Data sets
37 views (last 30 days)
Show older comments
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
0 Comments
Answers (3)
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
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.
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
Andrei Bobrov
on 30 Sep 2012
Edited: Andrei Bobrov
on 30 Sep 2012
The initial array yourmatrix with size (75000 x N).
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!