% STRUCTSUM - calculate the sums of all the fields in a struct

function m = structsum(s)

    thefields = fields(s);
    
    for n=1:length(s)
        for k=1:length(thefields)
            m.(thefields{k})(n) = nansum(s(n).(thefields{k}));
        end
    end
