# How can i compute the mean of specific number of table rows?

2 views (last 30 days)

Show older comments

##### 0 Comments

### Accepted Answer

Cong Ba
on 9 Aug 2017

Try reshape:

a = randn(100,1); % assume this is the column you have

b = reshape(a,[10,10]); % reshape it so each column has 10 rows

avg = mean(b);

##### 4 Comments

Cong Ba
on 10 Aug 2017

### More Answers (2)

Andrei Bobrov
on 9 Aug 2017

n = 278984;

t = minutes(10*(1:n)');

D = randi(255,n,2); % Let D - your data (278984 x 2)

TT = timetable(t,D(:,1),D(:,2));

TT_out = retime(TT,'hourly','mean');

##### 2 Comments

Andrei Bobrov
on 10 Aug 2017

Edited: Andrei Bobrov
on 10 Aug 2017

a.x_10_double = [a.x_10_{:}]';

TT = table2timetable(a(:,[1,3]),'RowTimes','x08_Jul_100_10_00');

TT_out = retime(TT,'hourly','mean');

or

a2 = table(a{:,1},[a{:,2}{:}]','v',{'datetime','x_10_double'})

a2.groups = hour(a2{:,1});

a_out = varfun(@mean,a2,'Group','groups');

Peter Perkins
on 10 Aug 2017

Add a grouping variable to your table and use varfun. Something like

n = ceil(height(t)/10);

g = repelem(1:n,10)';

t.Group = g(1:height(t));

t.groupMeans = varfun(@mean,t,'GroupingVariable','Group')

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!