A common approach in robotics is to learn tasks by generalizing from special cases given by a so-called demonstrator. In this paper, we apply this paradigm and present an algorithm that uses a demonstrator (typically given by a trajectory optimizer) to automatically synthesize feedback controllers for steering a system described by ordinary differential equations into a goal set. The resulting feedback control law switches between the demonstrations that it uses as reference trajectories. In comparison to the direct use of trajectory optimization as a control law, for example, in the form of model predictive control, this allows for a much simpler and more efficient implementation of the controller. The synthesis algorithm comes with rigorous convergence and optimality results, and computational experiments confirm its efficiency.