wolffd@0: function T2 = sumv(T1, sum_over) wolffd@0: % wolffd@0: % Like the built in sum, but will sum over several dimensions and then squeeze the result. wolffd@0: wolffd@0: T2 = T1; wolffd@0: for i=1:length(sum_over) wolffd@0: if sum_over(i) <= ndims(T2) % prevent summing over non-existent dimensions wolffd@0: T2=sum(T2, sum_over(i)); wolffd@0: end wolffd@0: end wolffd@0: T2 = squeeze(T2);