You could visit two or three cities in Spain in 9 days, but you won't even start to get to know them in this short amount of time. Even dividing these 9 days between Barcelona and Madrid is a stretch. I would suggest picking a city and exploring it, with day trips. Madrid is perfect for this goal.
It's the same deal with Portugal. Go to Lisbon, visit Sintra while you are there, or go to Porto and lounge around... There is no reason to be rushing around the country when you have so little time.
If you choose Lisbon, Madrid or Barcelona as your destinations, consider renting an apartment instead of a hotel. Good deals to be had are here: http://www.sweethomeabroad.com/ over 4 years ago