如何平均的阵列的单元阵列? [英] How to average over a cell-array of arrays?

查看:153
本文介绍了如何平均的阵列的单元阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有同等大小的阵列的单元阵列 C ,即尺寸(C {N})= [毫升...] 任何 N 。我怎样才能获得的意思是值(平均在单元格数组索引 N )在一次扫描所有的数组元素呢?我想过使用 cell2mat 的意思是,但前者不添加另一个维度,但变化→* N 。并手动循环当然需要像永远...

I have a cell array c of equal-sized arrays, i.e. size(c{n}) = [ m l ... ] for any n. How can I get the mean values (averaging over the cell array index n) for all array elements in one sweep? I thought about using cell2mat and mean but the former does not add another dimension but changes l to l*n. And looping manually of course takes like forever...

推荐答案

如果您所有的数组大小相同,它更有意义将它们存储在一个矩阵,而不是一个单元阵列。这使得它更容易地在它们之间执行操作,例如取平均值。您可以使用函数为ndims 并的CAT

If all of your arrays are the same size, it makes more sense to store them in a matrix rather than a cell array. That makes it easier to perform operations across them, like taking the mean. You can convert your data to a matrix using the functions NDIMS and CAT:

dim = ndims(c{1});          %# Get the number of dimensions for your arrays
M = cat(dim+1,c{:});        %# Convert to a (dim+1)-dimensional matrix
meanArray = mean(M,dim+1);  %# Get the mean across arrays

这篇关于如何平均的阵列的单元阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆