We study the behaviour of the inverse participation ratio and the localization transition in infinitely large random matrices through the cavity method. Results are shown for two ensembles of random matrices: Laplacian matrices on sparse random graphs and fully-connected Levy matrices. We derive a critical line separating localized from extended states in the case of Levy matrices. Comparison between theoretical results and diagonalization of finite random matrices is shown.