%takes matrix in log space, sums in base 10, returns vector in log space

function[result] = sumlog(mat,dim)


    [dim1 dim2] = size(mat);

    bmax = max(mat,[],dim);
    
    if dim==1
                
        mmax = repmat(bmax,dim1,1);
        
    elseif dim==2
        
        mmax = repmat(bmax,1,dim2);

    end
        
    result = bmax+log(sum(exp(mat-mmax),dim));

