Is it possible to assign fields to entries by category? I want to show some fields depending in the category selected for the entry but within the editing stage. is it possible?

If not, then how can i check if the entry is in a category in the template and output a field group.

thanks ahead!
Could you use the entry types to achieve the same thing?
https://buildwithcraft.com/features/entry-types