Depends what you hope to do. Barcelona could keep you busy for 5 days no problem and you would never need to leave the city. Also there is a lot of day trips you can take by train.
Madrid, can be a quick trip but the best parts in my opinion our jsut outside of the city: TOledo, Segovia, El Escorial all reachable by bus/train but for this it's better to have a car.
I lived in Madrid, and now live in Barcelona. Both are wonderful, but if you want to do some driving pick Madrid, if you want to walk alot and take a train or two shoot for Barcelona.
Either way keep an open mind and taste a lot of food and wine where ever you go!