Average of every 25 rows in a table

18 ビュー (過去 30 日間)
Reem RA
Reem RA 2022 年 7 月 3 日
コメント済み: Reem RA 2022 年 7 月 5 日
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

採用された回答

Abhishek Tiwari
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
output = 40×10
0.5329 0.5851 0.5010 0.5203 0.4864 0.3876 0.5029 0.5378 0.4667 0.4931 0.5315 0.5217 0.5169 0.5313 0.5383 0.4457 0.4606 0.5541 0.4590 0.6092 0.4712 0.4571 0.4326 0.4300 0.5599 0.5561 0.5522 0.5662 0.5468 0.5205 0.4788 0.4865 0.4554 0.4486 0.5526 0.5052 0.3405 0.5116 0.5173 0.5189 0.4536 0.3814 0.5256 0.4594 0.4725 0.5219 0.5299 0.4808 0.4840 0.5354 0.3794 0.3971 0.4839 0.5850 0.3706 0.5975 0.6139 0.5391 0.3941 0.5435 0.5360 0.5580 0.5243 0.5750 0.4471 0.4273 0.5424 0.4981 0.4707 0.4634 0.4814 0.4900 0.6158 0.4795 0.4305 0.4495 0.4998 0.5014 0.4877 0.4645 0.4974 0.4583 0.4654 0.6242 0.4960 0.5045 0.4318 0.4466 0.3654 0.5716 0.4906 0.4275 0.3932 0.5329 0.5218 0.5332 0.4855 0.4368 0.3938 0.4639
  3 件のコメント
Abhishek Tiwari
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.
Reem RA
Reem RA 2022 年 7 月 5 日
Thank you, I tried it and it worked.

サインインしてコメントする。

その他の回答 (1 件)

Akira Agata
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
Akira Agata 2022 年 7 月 4 日
Hi @Rulla RA-san,
I just wanted to create "group number".
For more information, please take a look at the following.
Reem RA
Reem RA 2022 年 7 月 5 日
Thanks a lot, this worked well too!!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by