Analytic functions of M-matrices and generalizations