## How do I get the mean of always 4 columns

### Antonio Melieni (view profile)

on 15 Apr 2019
Latest activity Commented on by Antonio Melieni

### Antonio Melieni (view profile)

on 17 Apr 2019

Hi,
I have a 527040 x 16 double array
I need the row mean of always 4 clomuns
So I need the row mean of column 1:4 5:8 9:12 13:16
So I want the mean([1:4],2) and mean([5:8],2)
but i dont want to wirte it down in that way. I need an more automatic way to do it
any ideas?

### Release

R2018b

on 15 Apr 2019

on 15 Apr 2019

AA=permute(reshape(A.',4,1,[]),[2,1,3]); % where A is size 527040 X 16
AAA=squeeze(mean(AA));
% if you want to reshape it as matrix then
% reshape(AAA,size(A,1),[]) %% edit removed transpose

Antonio Melieni

### Antonio Melieni (view profile)

on 15 Apr 2019
The transpose doesnt help.... I get an 4 X 527040 array then....
Matt J

### Matt J (view profile)

on 15 Apr 2019
Both the permute operation and the transpose operation allocate arrays the same size as A. sepblockfun avoids this.

on 15 Apr 2019
@Antonio:Matt‘s file exchange is Perfect why not use his solution then?

on 15 Apr 2019
Edited by Matt J

### Matt J (view profile)

on 15 Apr 2019

Then you would do,
result = sepblockfun(yourArray, [1,4],'mean');

Antonio Melieni

### Antonio Melieni (view profile)

on 15 Apr 2019
Thanks, but thats a bit to complicated :)
Catalytic

### Catalytic (view profile)

on 15 Apr 2019
@Antonio,
The only way I can Matt J's one line solution as being "too complicated" is that this is homework. So, you're not allowed to use third-party routines like sepblockfun as is, and it is a tedious matter for you to try to decipher what it is doing and adapt it to your assignment.
Antonio Melieni

on 17 Apr 2019
@Matt