Average each element of cell array

9 ビュー (過去 30 日間)
Carmel Howe
Carmel Howe 2015 年 10 月 25 日
コメント済み: Paolo 2018 年 7 月 14 日
I have a 10x1 cell of separate events with each array having a size 384(time) x 5328(pixel). I want to average each pixel across each separate event. For example A{1,1}(1,1); averaged with A{2,1}(1,1) etc etc Thanks

採用された回答

Stephen23
Stephen23 2015 年 10 月 25 日
編集済み: Stephen23 2015 年 10 月 25 日
The easiest way is to use cat to concatenate the cell array of numeric arrays into a simple 3D numeric array, and then use the inbuilt mean function with its optional second argument to take the average along the third dimension:
X = your cell array
Y = cat(3,X{:});
out = mean(Y,3);
Here is a simple example showing how this works:
>> X = {[1,2,3;4,5,6],[0,2,4;6,8,10]};
>> Y = cat(3,X{:})
Y(:,:,1) =
1 2 3
4 5 6
Y(:,:,2) =
0 2 4
6 8 10
>> out = mean(Y,3)
out =
0.5 2 3.5
5 6.5 8
  3 件のコメント
Chalita
Chalita 2018 年 7 月 14 日
編集済み: Chalita 2018 年 7 月 14 日
Hi. I'm new to matlab. This answer is very helpful for what I'm trying to do. Thanks.
I have about 1,000 cells in my cell array. What do I need to do if instead of taking average across all cells, I want to take average every 4 cells. That is, instead of 1 output cell, I should have 1,000/4 cells. Thanks
Paolo
Paolo 2018 年 7 月 14 日
@Chalita you should open a new question for your query.

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

その他の回答 (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