Alternating direction methods for solving a class of Sylvester-like matrix equations