我有一个相等大小的数组的单元格数组c ,即对于任何n , size(c{n}) = [ ml ... ] 。如何一次扫描所有数组元素的mean (在单元数组索引n取mean )?我考虑过使用cell2mat和mean但是前者并没有添加另一个维度,而是将l更改为l*n 。手动循环当然需要永远...
回答:
如果所有数组的大小都相同,则将它们存储在矩阵而不是单元格数组中会更有意义。这样可以更轻松地对它们进行操作,例如取平均值。您可以使用
NDIMS和
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
更多&回答...