Localized bases play an important role in understanding electronic structure. In periodic insulators, a natural choice of localized basis is given by the Wannier functions which depend on a choice of unitary transform known as a gauge transformation. Over the past few decades, there have been many works that have focused on optimizing the choice of the gauge so that the corresponding Wannier functions are maximally localized or reflect some symmetry of the underlying system. In this work, we consider fully nonperiodic materials where the usual Wannier functions are not well defined and gauge optimization is impractical. To tackle the problem of calculating exponentially localized generalized Wannier functions in both periodic and nonperiodic systems, we discuss the 'iterated projected position (IPP)"algorithm. The IPP algorithm is based on matrix diagonalization and therefore unlike optimization-based approaches, it does not require initialization and cannot get stuck at a local minimum. Furthermore, the IPP algorithm is guaranteed by a rigorous analysis to produce exponentially localized functions under certain mild assumptions. We numerically demonstrate that the IPP algorithm can be used to calculate exponentially localized bases for the Haldane model, the Kane-Mele model (in both Z2 invariant even and Z2 invariant odd phases), and the px+ipy model on a quasicrystal lattice.