How do I find the sum of values in my cell array?

1 次查看(过去 30 天)
I currently have a set of data like so:
i1x35 double
1570 0.000636942675159236 0.0306264386699255
1x27 double
1476 0.000677506775067751 0.0325769029212623
1x23 double
1067 0.000937207122774133 0.0450642068526552
1x25 double
1172 0.000853242320819113 0.0410268845663678
1x19 double
864 0.00115740740740741 0.0556522091571564
1x29 double
1327 0.000753579502637528 0.0362347465800928
1x27 double
1265 0.000790513833992095 0.0380106788235440
1x19 double
1088 0.000919117647058824 0.0441944013895065
1x43 double
2122 0.000471253534401508 0.0226595234268535
1x31 double
1367 0.000731528895391368 0.0351744760144719
1x27 double
1416 0.000706214689265537 0.0339572801636886
1x31 double
1743 0.000573723465289730 0.0275866372414131
1x25 double
1359 0.000735835172921266 0.0353815369475961
1x21 double
811 0.00123304562268804 0.0592891599405464
1x29 double
1221 0.000819000819000819 0.0393804330153834
1x23 double
1027 0.000973709834469328 0.0468193853084548
1x33 double
1730 0.000578034682080925 0.0277939356715509
1x23 double
1309 0.000763941940412529 0.0367330089471223
1x23 double
1130 0.000884955752212389 0.0425517776210470
1x27 double
1211 0.000825763831544178 0.0397056223879299
1x21 double
817 0.00122399020807834 0.0588537438332719
1x23 double
1084 0.000922509225092251 0.0443574803614235
1x21 double
858 0.00116550116550117 0.0560413854449687
1x29 double
1282 0.000780031201248050 0.0375066370606733
1x31 double
1465 0.000682593856655290 0.0328215076530943
Currently my code looks like this:
sumd = sum(newnest{:,2});
I get an error that says: Error using sum Too many input arguments.
Error in A074gacsinsp (line 312) sumd = sum(newnest{:,2});
Can someone point out where I went wrong? I want to sum up all the values in the 2nd column. ie.. 1570+1476+1067+....
  1 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2016-4-2
@Xi you don't need to post all thee data, just post a short example then explain your problem, probably with an expected result

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-2
编辑:Azzi Abdelmalek 2016-4-2
A={[1 2], [1 2 3 4 5],[0 8 7 6]}
out=cellfun(@sum,A)
  11 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2016-4-5
编辑:Azzi Abdelmalek 2016-4-5
A = {[1 2 3] [1843] [5.4259e-04];
[4 5 6 7] [1464] [6.8306e-04]}
out=sum(cell2mat(A(:,2)))
Or
out=sum([A{:,2}])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by