Transitions between the states with uniform and vortex distributions of magnetization in ferromagnetic nanoparticles under the action of an inhomogeneous magnetic field