Summing regions of a matrix that do not over lap in matlab -
i trying sum vector in groups of twenty length of vector e.g. 7628. can't figure out way output vector sums of sets of twenty or
ans = [sum(a(1:20) sum(a(21:30)....].
since 7600 evenly divisible 20, can reshape , sum:
a = rand(7600,1); sum(reshape(a,20,7600/20))
edit addressing comment non evenly divisible lengths
b = 20; sz = size(a); % last elements exclude excl = mod(sz(1),b); % sum reshape , sum excluded separately [sum(reshape(a(1:end-excl), b, fix(sz(1)/b))), sum(a(end-excl+1:end))]
Comments
Post a Comment