We study the long-time behavior of localized solutions to linear or semilinear parabolic equations in the whole space $$\mathbb {R}^n$$ , where $$n \ge 2$$ , assuming that the diffusion matrix depends on the space variable x and has a finite limit along any ray as $$|x| \rightarrow \infty $$ . Under suitable smallness conditions in the nonlinear case, we prove convergence to a self-similar solution whose profile is entirely determined by the asymptotic diffusion matrix. Examples are given which show that the profile can be a rather general Gaussian-like function, and that the approach to the self-similar solution can be arbitrarily slow depending on the continuity and coercivity properties of the asymptotic matrix. The proof of our results relies on appropriate energy estimates for the diffusion equation in self-similar variables. The new ingredient consists in estimating not only the difference w between the solution and the self-similar profile, but also an antiderivative W obtained by solving a linear elliptic problem which involves w as a source term. Hence, a good part of our analysis is devoted to the study of linear elliptic equations whose coefficients are homogeneous of degree zero.