Adding cell array entries
1 次查看(过去 30 天)
显示 更早的评论
Suppose you have a 162*24 cell array called CC and each cell array entry consist of a matrix.
How would you add CC{1,1}+CC{2,1}+CC {3,1}.....CC{162,1}
and then to the same for the remaining 23 columns.
I dont need the sum but all matrices within each cell entry have to be added.
Thanks
0 个评论
采纳的回答
Walter Roberson
2020-8-23
nd = ndims(CC{1,1});
sol = sum(cat(ndims+1, CC{:,1}),ndims+1);
There are also approaches using the more obscure fold() operation.
4 个评论
更多回答(1 个)
Sara Boznik
2020-8-23
for i=1:24
sol=sum((CC(:,i)))
end
1 个评论
Walter Roberson
2020-8-23
No, not for a cell array. sum() does not apply to cell arrays.
Also, you are overwriting all of sol each iteration.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!