Amrmsmb
Amrmsmb

Reputation: 1

how to get the sum of matrix elements

i have the floolowing elements and i want to sum them all, i referred to this link but it gives me the summation of the rows, and i want the total sum of the whole elements posted below.

[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]

Upvotes: 0

Views: 52

Answers (2)

cwissy
cwissy

Reputation: 513

if you use the colon operator A(:) this returns the elements in A as a single column, so then you can simply call sum(A(:)) and it will sum of all the elements

Upvotes: 2

xenoclast
xenoclast

Reputation: 1635

You can sum the rows to get a column vector of sums, and then sum that:

sum(sum(A));

Upvotes: 0

Related Questions