The calculation of off-diagonal matrix elements has various applications in fields such as nuclear physics and quantum chemistry. In this paper, we present a noisy intermediate scale quantum algorithm for estimating the diagonal and off-diagonal matrix elements of a generic observable in the energy eigenbasis of a given Hamiltonian. Several numerical simulations indicate that this approach can find many of the matrix elements even when the trial functions are randomly initialized across a wide range of parameter values without, at the same time, the need to prepare the energy eigenstates.