Of course. Say, if you are training Chespin and you are up against Honedge, you still want to defeat it, and you get low HP, won't you like to restore Chespin so that you are up to it ?
Now, if you are not far, then just switch, defeat the wild Pokémon and go to the center.