如何获得矩阵元素的总和

时间:2015-04-30 09:18:22

标签: matlab

我有floolowing元素,我想总结它们,我提到这个link,但它给了我行的总和,我想要下面发布的整个元素的总和。

[25.999985, 26.999994, 31.00001, 39.000046, 53.000084, 71.000038, 80.999962,    
78.999931, 71.999954;
23.999996, 26.000015, 32.000023, 45.000038, 64.000046, 76.000031, 76.000023,  
70.000015, 65.000023;
21.000031, 29.000027, 39.000027, 61.000008, 85.999985, 88.999992, 75.000023, 
64.000031, 63.000023;
26.000048, 39.000027, 53, 78.999962, 104.99993, 100.99995, 79, 67.000015, 
68.000023;
44.000015, 56.000004, 67.999992, 86.999969, 105.99995, 100.99998, 82.000023, 
74.000038, 77.000031;
66.999962, 73.999969, 78.999985, 86, 96.000023, 96.000038, 90.000053, 
90.000046, 94.000046;
79.999969, 83.999969, 85.999992, 87.000015, 92.000031, 102.00002, 112.00001, 
117.99999, 122.99999;
82.999985, 86.999985, 90.999992, 92.000008, 97.000031, 115.00001, 134.99995, 
142.99997, 148.99995;
82.000015, 85.000008, 93.999969, 100.99993, 109.9999, 128.99989, 148.99989, 
159.99988, 161.99989]

2 个答案:

答案 0 :(得分:2)

如果使用冒号运算符A(:),则会将A中的元素作为单个列返回,因此您只需调用sum(A(:))即可将所有元素的总和

答案 1 :(得分:0)

您可以对行求和以获得总和的列向量,然后求和:

sum(sum(A));