A Characterization for Generalized Inverses of Matrices