sum values in a cell array
272 次查看(过去 30 天)
显示 更早的评论
Hello! I have
a={0.006;0.45;0.1;0.23;0.12}
and I want to sum all the values in a, how can i do?
0 个评论
采纳的回答
Azzi Abdelmalek
2016-4-29
编辑:Azzi Abdelmalek
2016-4-29
sum([a{:}])
or you can use cell2mat
b=cell2mat(a)
out=sum(b)
0 个评论
更多回答(1 个)
BINGXIN YAN
2021-7-12
What if the cell is more complicated?
I have a{1,1}=[1,1];a{1,2}=[0,1];a{1,3}=[2,5],
and I want to sum all the values in a{1,:}(1), for example
a{1,1}(1)+a{1,2}(1)+a{1,3}(1)=1+0+2, how can I do except restoring a{1,:}(1) in another matrix or array.
0 个评论
另请参阅
类别
在 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!