Average of every 25 rows in a table
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Abhishek Tiwari
2022년 7월 3일
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
Abhishek Tiwari
2022년 7월 5일
편집: Abhishek Tiwari
2022년 7월 5일
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.
추가 답변 (1개)
Akira Agata
2022년 7월 3일
편집: Akira Agata
2022년 7월 3일
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
Akira Agata
2022년 7월 4일
I just wanted to create "group number".
For more information, please take a look at the following.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!