A method to determine the M2 beam quality from the electric field in a single plane