How to sum cells/structs in MATLAB
I am trying to add vertically the lists of a database like DB (see below) contained in a cell. DB={ {[11 12]} {[13 14]} {[15 16]} {[17 18]} {[19 20]}; {[21 22]} {[23 24]} {[25 26]} {[27 28]} {[29 30]}; {[31 32]} {[33 34]} {[35 36]} {[37 38]} {[39 40]}} I would like to get: [33 36] [69 72] [75 78] [81 44] [ 87 90 ] I tried with a for loop (see below), but it takes too much time. sum=[ ] for j=1:5 sumi=0 for i=1:3 sumi=sumi+ c2{i,j}{1} end sum=[sum sumi] end How could I do this with a minimum of for loops or, even better, without any loop?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.