Question

I am trying to perform a binning average. I am using the code:

Avg = mean(reshape(a,300,144,27));
AvgF = squeeze(Avg);

The last line gets rid of singleton dimensions.

So as can be seen I am averaging over 300 points. It works fine except for times when I have a total number of points not equal to a multiple of 144*300.

Is there any way to make this binning average work even when the total number of points is not a multiple of 144*300?

EDIT: Sorry if my question sounded confusing. To clarify...

I have a file with 43200 rows and 27 columns. I am averaging by binning 300 rows at a time, which means in the end I am left with a matrix of size 144-by-27.

My code as I wrote it above works only when I have exactly 43200 rows. In some cases I have 43199, 43194, etc.. The reshape function works when I have a total number of rows that is a multiple of 300 (the bin size). Is there a way to make this binning average work when my total number of rows is not a multiple of 300?

Was it helpful?

Solution

I think I understand the problem better now...

If a is the data read from your file (of size N-by-27, where N is ideally 43,200), then I think you would want to do the following:

nRemove = rem(size(a,1),300);  %# Find the number of points to remove
a = a(1:end-nRemove,:);        %# Trim points to make an even multiple of 300
Avg = mean(reshape(a,300,[],27));
AvgF = squeeze(Avg);

This will remove points such that the number of rows in a will be a multiple of 300. Then your reshape and average should work. Note that I use [] in the call to RESHAPE, which lets it figure out what the number of column should be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top