【问题标题】:How to sum up all the arrays (identical sizes) inside a cell array?如何总结单元格数组中的所有数组(相同大小)?
【发布时间】:2018-02-09 11:11:37
【问题描述】:

例如,我有以下单元格数组:

a = [1,2,3; 1,5,8; 6,5,0; 0,0,2];
A = cell(3,4);
for i = 1:3
    for j = 1:4
        A{i,j} = (j-i)*a;
    end
end

我如何总结所有元素,即A{1,1} + A{1,2} + ... + A{3,4}

【问题讨论】:

    标签: arrays matlab sum cell cell-array


    【解决方案1】:

    Concatenate 沿第三维每个单元格中的矩阵,然后沿第三维sum

    TD = cat(3, A{:});    %Converting the cell array to a 3D array
    result = sum(TD, 3);  %Summation of 3D slices
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2023-01-03
      • 2020-01-15
      相关资源
      最近更新 更多