Average of every 25 rows in a table
32 views (last 30 days)
Show older comments
Hello,
I have a table of 10 columns and 1000 rows. I would like to take the average of each column for every 25 rows. How to code that please?
Thank you
0 Comments
Accepted Answer
Abhishek Tiwari
on 3 Jul 2022
Hi,
This might work,
% Sample data
data = rand(1000, 10);
% Calculating Output Dimension (#columns will be same)
rows = 1000/25;
output = ones(rows, 10);
% Start first 25 entries then compute mean and increase index for next
% 25 entries
for row = 0:rows-1
output(row+1, :) = mean(data(25*row+1:25*(row+1),:));
end
output
More Answers (1)
Akira Agata
on 3 Jul 2022
Edited: Akira Agata
on 3 Jul 2022
Another possible solution:
% Sample data
data = rand(1000, 10);
% Grouping
group = repelem(1:size(data, 1)/25, 25)';
% Apply mean function for each group
output = splitapply(@mean, data, group);
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!