Mean of nested cell arrays

3 次查看(过去 30 天)
I have attached the 2 arrays which I am trying to calculate the mean, independently.
mycell.mat is a {10x1}{3x1}{7x1} cell. I need to calculate the mean of the 10 values within the nested cells.
So I need the: mean of mycell{1:10,1}{1,1}(1,1)
mean of mycell{1:10,1}{1,1}(2,1)
mean of mycell{1:10,1}{1,1}(3,1) and so on
mean of mycell{1:10,1}{2,1}(1,1)
mean of mycell{1:10,1}{2,1}(2,1)
mean of mycell{1:10,1}{2,1}(3,1) and so on
mean of mycell{1:10,1}{3,1}(1,1)
mean of mycell{1:10,1}{3,1}(2,1)
mean of mycell{1:10,1}{3,1}(3,1) and so on
Thank you

采纳的回答

Stephen23
Stephen23 2018-7-6
>> M = cell2mat(permute(cat(3,cv_perf{:}),[2,1,3]));
>> Z = mean(M,3)
Z =
0.058748 0.078402 0.095877
0.094780 0.133897 0.116949
0.144421 0.190915 0.140248
0.133917 0.158366 0.152102
0.143377 0.130409 0.130549
0.183644 0.180682 0.164413
0.084289 0.158605 0.090256

更多回答(1 个)

Akira Agata
Akira Agata 2018-7-6
How about the following? The result out is 10-by-1 array.
- out(1) is mean of cv_perf{1}{1}(1) ~ cv_perf{10}{1}(1)
- out(2) is mean of cv_perf{1}{1}(2) ~ cv_perf{10}{1}(2)
...
- out(10) is mean of cv_perf{1}{1}(10) ~ cv_perf{10}{1}(10)
load('mycell.mat')
c = [cv_perf{1:10}];
d = cell2mat(c(1,:));
out = mean(d,2);
  1 个评论
ErikaZ
ErikaZ 2018-7-6
编辑:ErikaZ 2018-7-6
The result out is 7x1 and it only does the mean of the first 3x1 block. If dimensions and shapes are kept, I should have a cell of 3x1 with 7 means in each row cell.
Do not worry about mycell2.mat. I am going to erase it from the Question but I still need a solution for mycell.mat

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by