How to average every n files in a cell array?

1 回表示 (過去 30 日間)
Chalita
Chalita 2018 年 7 月 15 日
回答済み: Hernaldo Leyton 2018 年 11 月 15 日
Hi.I'm really new to matlab. I have about 1,000 cells in my cell array. How to, instead of taking average across all cells, take average every 4 cells. That is, instead of 1 output cell, I should have 1,000/4 cells. Below is what I have so far. The output (DaySMAv) from this is a single cell from averaging all cells in DATA, which is not what I want.
DATA = cat(3,data{:}); DaySMAv = mean(DATA,3);
Thanks.

採用された回答

Jan
Jan 2018 年 7 月 15 日
DATA = cat(3, data{:});
siz = size(DATA);
DATA = reshape(DATA, siz(1), siz(2), 4, []);
DaySMAv = squeeze(mean(DATA, 3));
  1 件のコメント
Chalita
Chalita 2018 年 7 月 16 日
Jan, thanks a lot. It worked!!

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

その他の回答 (1 件)

Hernaldo Leyton
Hernaldo Leyton 2018 年 11 月 15 日
Hi, I have a similar example but there are 409 cell arrays and I need to average every 24, that is 409/24, so when reshape is applied it does not work. Please, can you help me with an alternative?
Thank you

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by