简体   繁体   English

计算嵌套单元格的平均值

[英]Calculate the average of nested cells

Suppose that we have this cell array: 假设我们有这个单元格数组:

data = {{[1,2,3],[3,6,3]},{[6,8,2],[1,1,1]},{[4,8,3],[1,2,3]},{[5,1,3],[1,0,2]}};

we have four main cells and in every cell we have two cells. 我们有四个主要细胞,在每个细胞中我们有两个细胞。 I want average between four main cells like this: 我希望平均四个主要单元格如下:

Average 1 between:
1   2   3
6   8   2
4   8   3
5   1   3
---------
4   4.75   2.75

Average 2 between:
3   6   3
1   1   1
1   2   3
1   0   2
---------
1.5  2.25  2.25

Finally, we should gather these two results in a cell array. 最后,我们应该在单元格数组中收集这两个结果。 What is the fastest way to do this, with minimum number of loops? 以最少的循环次数,最快的方法是什么?

Follow Adriaan's advise, but: 按照Adriaan的建议,但是:

x = reshape([data{:}],2,[])';
means = reshape(mean(cell2mat(x)),[],2)'    
means =    
    4.0000    4.7500    2.7500
    1.5000    2.2500    2.2500

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM