finding the average of specific rows in each column

Hi,
I have a matrix variable called "out" and it consists of 24 columns and 200000 rows. I want the average of the consecutive 24 rows of every column. The example below illustrates what I want.
average of rows 1-24 from every column (24 columns in total) average of rows 25-49 from every column (24 columns in total) everage of rows 50-74 from every column (24 columns in total) and so on
I really appreciate your help.

 Accepted Answer

a=rand(200,24)
[n,m]=size(a);
idx=mod(-n,24);
a(end+1:end+idx,:)=0;
[n,m]=size(a);
b=permute(reshape(a',m,24,[]),[2 1 3]);
c=mean(b);
out=reshape(c(:),size(c,3),m)

4 Comments

I am sorry for giving comment here, because I have similar problem. How do I find the average only for certain row, for example, find average only for 1st row, 25th row, 50th row, and so on?
@dydy: Please do not highjack a foreign thread. Open a new thread for a new question. Actually it is not useful, if I post an answer here. But the solution is easy and the faster you get help the better.
Result = mean(X([1, 25, 50], :), 2)
But please open new threads in the future. Thanks.
Sorry, I don't mean to hijack. I don't make it again.
@azzi what is the
[n,m]=size(a);
and
a(end+1:end+idx,:)=0;
used for ?

Sign in to comment.

More Answers (1)

[m,n]=size(out);
m=floor(m/24)*24;
out=out(1:m,:); %throw away extra rows
out=mean(reshape(out,24,[]));
out=reshape(out,[m/24,n])

Asked:

AA
on 3 Oct 2014

Commented:

on 7 Jan 2018

Community Treasure Hunt

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

Start Hunting!