Average of every 25 rows in a table
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Reem RA
el 3 de Jul. de 2022
Comentada: Reem RA
el 5 de Jul. de 2022
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 comentarios
Respuesta aceptada
Abhishek Tiwari
el 3 de Jul. de 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
3 comentarios
Abhishek Tiwari
el 5 de Jul. de 2022
Editada: Abhishek Tiwari
el 5 de Jul. de 2022
Just defining dimension of output table... It is better than create one dynamically, saves time. When we average every 25 rows for each column dimension of output table is reduced from 1000 to 1000/25 (=40) but column remains same.
Más respuestas (1)
Akira Agata
el 3 de Jul. de 2022
Editada: Akira Agata
el 3 de Jul. de 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);
3 comentarios
Akira Agata
el 4 de Jul. de 2022
I just wanted to create "group number".
For more information, please take a look at the following.
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!