Why did some dinosaurs have spikes and plates?

Spikes and back plates could warn predators, regulate heat, or both.