Calculate mean of every nth row in a table

14 ビュー (過去 30 日間)
chiefjia
chiefjia 2021 年 10 月 26 日
コメント済み: chiefjia 2021 年 10 月 28 日
Dear MATLAB experts,
I'm trying to get the mean value of every third row starting from the first row in a table. So, I would like to get the mean value of the 1st, 4th, 7th, 10th, 13th, 16th, 19th... up to the 666679th row and apply the same approach to the other remaining rows, 2nd, 5th, 8th, 11th, 14th... up to the 666680th row and to the 3rd, 6th, 12th, 15th, 18th... up to the 666681th row.
This means that I would like to get 3 mean values and I want to do this for the column of the table you will find attached to this post.
I would really appreciate your help since I don't even know how to approach this problem. Thank you in advance.

採用された回答

André Kucharzewski
André Kucharzewski 2021 年 10 月 26 日
>> v = randi(100,100,1)
>> mean(v(1:2:end)
or mean(v(1:3:end)
in your case end could be 666679
  3 件のコメント
DGM
DGM 2021 年 10 月 28 日
Yes. That will take the means of three interleaved samplings of v.
Consider the example:
v = [1 2 3 1 2 3 1 2 3 1 2 3];
% samples
v1 = v(1:3:end)
v1 = 1×4
1 1 1 1
v2 = v(2:3:end)
v2 = 1×4
2 2 2 2
v3 = v(3:3:end)
v3 = 1×4
3 3 3 3
% means
mean(v1)
ans = 1
mean(v2)
ans = 2
mean(v3)
ans = 3
chiefjia
chiefjia 2021 年 10 月 28 日
Perfect, thanks a lot!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by