Yes. Spain is a diverse and dynamic country. While you won't see everything in Spain, 10 days is enough time, especially for first time visitors, to explore both Madrid and Barcelona. Travel time between most Spanish cities isn't significant, even by train.