如何计算matlab中cellarray元素的平均值?

时间:2017-12-28 14:08:15

标签: matlab matrix mean cell-array

我的尺寸为 64x8 的cellarray A 包含以下尺寸的元素,

520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double
520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double
520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double    520x1 double
...................

现在我需要在每列的8行中使用 MEAN ,这样我每行只会得到一个 520X1 单元格。

所以,在对行应用平均值之后,我的输出应该是类似的,

520x1 double
520x1 double
520x1 double
520x1 double
............

因此,我的输出将是从64x8转换而来的64x1单元阵列。

我尝试使用以下命令

执行此操作
  

avgCell = {mean(cat(3,C {:}),3)}

但是,它只为 1X1 单元格数组提供了一个维度为 520X1 的单元格。

请更正我,并建议我是否有任何功能来处理这个问题。如果我需要循环来执行此操作,还请告诉我?

1 个答案:

答案 0 :(得分:0)

% Create sample data...

A = cell(64,8);

for i = 1:64
    for j = 1:8
        A{i,j} = rand(520,1);
    end
end

% Calculate column-wise means...

B = mean(cell2mat(A),2);

% Reshape the result into a cell array...

C = mat2cell(B,repmat(520,64,1),1);