Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想矢量化总和的计算
A{1} + A{2} + ... + A{end}
其中A是一个向量元胞数组,每个 A{i} 是一个 nxn 数值矩阵。
A
有很多方法可以通过这种方式编写代码,但我想知道是否有一个聪明的方法只适合一两行代码。
您可以先连接,然后沿第三维求和:
[A{1:3}] = deal(ones(4)); %# each element of the cell array contains a 4-by-4 array of ones out = sum( cat(3,A{:}), 3); %# catenate, then sum