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 taking too much time.
How could I do this with the minimum of 'for' loops or even better, without any loop?
Thank you very much for your attention.
sum=[ ]
for j=1:5
sumi=0
for i=1:3
sumi=sumi+ c2{i,j}{1}
end
sum=[sum sumi]
end
33obtained? (3) What type of array do you need the result to be? What you show is 5 separate arrays.sum=[sum sumi], which creates a new array and copies the data into it. You should never do that inside a loop. Read about preallocation: mathworks.com/help/matlab/matlab_prog/preallocating-arrays.htmlsumas a variable name, you're shadowing the in-built function which can cause unexpected errors