例如,我有以下元胞数组:
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}
?
最佳答案
Concatenate沿三维的每个单元格中的矩阵,然后是 sum
沿着三维。
TD = cat(3, A{:}); %Converting the cell array to a 3D array
result = sum(TD, 3); %Summation of 3D slices
关于arrays - 如何总结单元格数组中的所有数组(相同大小)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48704550/