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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by