% STRUCTMEAN - calculate the mean of all the fields in a struct

function m = structmean(s)

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