gpt4 book ai didi

arrays - 如何对阵列的单元阵列进行平均?

转载 作者:太空宇宙 更新时间:2023-11-03 19:18:04 25 4
gpt4 key购买 nike

我有一个单元格数组 c 的大小相等的数组,即 size(c{n}) = [ m l ... ] 对于任何 n 。如何在一次扫描中获取所有数组元素的 mean 值(元胞数组索引 n 的平均值)?我考虑过使用 cell2matmean 但前者没有添加另一个维度,而是将 l 更改为 l*n .手动循环当然需要永远......

最佳答案

如果所有数组的大小都相同,则将它们存储在矩阵中而不是元胞数组中更有意义。这使得在它们之间执行操作变得更容易,比如取平均值。您可以使用函数将数据转换为矩阵 NDIMSCAT :

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

关于arrays - 如何对阵列的单元阵列进行平均?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5197597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com