corrected ill-shaped vectors: g = g(:)