MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何对阵列的单元阵列求平均? (https://www.labfans.com/bbs/showthread.php?t=26486)

poster 2019-12-14 20:13

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



[B]回答:[/B]

如果所有数组的大小都相同,则将它们存储在矩阵而不是单元格数组中会更有意义。这样可以更轻松地对它们进行操作,例如取平均值。您可以使用[URL="http://www.mathworks.com/help/techdoc/ref/ndims.html"]NDIMS[/URL]和[URL="http://www.mathworks.com/help/techdoc/ref/cat.html"]CAT[/URL]函数将数据转换为矩阵:

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

[url=https://stackoverflow.com/questions/5197597]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 20:40

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.