function M = sumdims(X,dims)

M=X;

for i=1:length(dims)
    M=sum(M,dims(i));
end

M = squeeze(M);

end