Just to add my biased opinion,
If you stay some time in Madrid, there are so many historic cities you can visit on a day trip (Segovia, Toledo, Avila, Guadalajara, Chinchon, even Salamanca and Cordoba at a pinch)
There are a few subtle differences between the 2 cities (apart from having an extra language to deal with in Barcelona). A lot of day time bars (ie eat and drink places) seem to shut early in Barcelona, around 9 or 10 oclock which is v. early for Spain (you have plenty of choices though). Also in a lot of bars in Madrid you will get a free aperitivo/tapa with your drink.
Madrid feels more of a (Latin-) World city whereas as is correctly pointed out Barca feels like a european city. There are an awful lot of places in Barca that sell Frankfurters, Hamburgers, Bratwurst etc, but this is not the case in Madrid.
I found that in Barcelona all the atractions tend to be a long distance from each other (but they are certainly worth visiting). THe area in Barcelona I don't like is the Eixample is I found clinical and monotonous. In Madrid you only have to walk 2 or 300 metres and the ambience of the neighbourhood completely changes.
Another oddity in Barca is that all the music I heard was English language. It seemed that there maybe would be a problem with either playing Spanish or Catalan music (a large size of Barca's population originate from outside Catalunya). In Madrid you can still listen to plenty of Pop, Dance, Rock, blues, Jazz etc but you will be exposed to more spanish and Latin- AMerican music.
Anyway, you will find Madrid an experience. Have fun!!!!!!
(PS It can get very cold in winter in Madrid and snow is not unknown)

Oh I forgot to add,
Add Bilbao to your list of top Spanish cities (well it is Basque I know, but feels Spanish to a visitor). It is definitely worth visiting, and not just for the Gugenheim. Check out the design of the bridges over the river, or take their metro and visit the Atlantic ocean. Only make sure you have a raincoat - it tends to rain a little in the Basque country.
_________________________
An English Bookseller in Madrid