How can i compute the mean of specific number of table rows?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a large amount of table data which is divided by date and time....to be more specific i have data that is per 10 minutes and i want to compute the mean of them per hour! In other words, i want ot compute the mean of my data per 10 rows until my data is finished! Is this possible and if yes....which command should i use?
0 个评论
采纳的回答
Cong Ba
2017-8-9
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 个评论
Cong Ba
2017-8-10
Andrei is using the timetable function which may better suit your need (you essentially have a time series). But if you want to manipulate data in matrix form (my code works for matrix form), you can try this function: table2array
更多回答(2 个)
Andrei Bobrov
2017-8-9
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 个评论
Andrei Bobrov
2017-8-10
编辑:Andrei Bobrov
2017-8-10
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
2017-8-10
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!