Average each element of cell array
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
Risposta accettata
Stephen23
il 25 Ott 2015
Modificato: Stephen23
il 25 Ott 2015
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 Commenti
Chalita
il 14 Lug 2018
Modificato: Chalita
il 14 Lug 2018
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!