mean of each column of a cell array that contains cell arrays
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Peter P
am 20 Dez. 2017
Kommentiert: Nandini Chatterjee
am 9 Apr. 2020
I have a cell array A(2x82). Cell array A contains in each cell cell arrays of different row sizes but equal column sizes. To be specific the column sizes are always 1.
First I want to combine the two rows of A and then calculate the mean of each column of cell array A. As a result i would get a 1x82 matrix.
Any suggestion? Thanks in advance, Peter
2 Kommentare
Walter Roberson
am 20 Dez. 2017
You have a 2 x 82 cell array of column vectors. When you take the mean of each column, I would expect a 2 x 82 numeric result, not a 1 x 82 numeric result.
Akzeptierte Antwort
Walter Roberson
am 20 Dez. 2017
cellfun(@mean, A) %provided you want a 2 x 82 numeric result.
1 Kommentar
Walter Roberson
am 20 Dez. 2017
sum(cellfun(@sum, A)) ./ sum(cellfun(@length, A))
Weitere Antworten (1)
Jos (10584)
am 20 Dez. 2017
Another approach, as all cells contain a column vector:
M = arrayfun(@(k) mean([A(k,1) ; A(k,2)]), 1:size(A,1))
4 Kommentare
Walter Roberson
am 9 Apr. 2020
size(A,2) is the size of the second dimension of the array A -- the number of columns. 1:size(A,2) is then a vector of numbers, 1, 2, 3, 4, ... until the number of columns of A
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!