Method for efficient magnetic analysis in an inhomogeneous field