We present experimental evidence of the successful closed-loop optimization of the dynamics of cold atoms in an optical lattice. We optimize the loading of an ultracold atomic gas minimizing the excitations in an array of one-dimensional tubes (3D-1D crossover) and we perform an optimal crossing of the quantum phase-transition from a Superfluid to a Mott-Insulator in a three-dimensional lattice. In both cases we enhance the experiment performances with respect to those obtained via adiabatic dynamics, effectively speeding up the process by more than a factor three while improving the quality of the desired transformation.