Do not combine Avila and Segovia in a day
No! It is not a good idea to combine Segovia and Avila on the same day.
If you combine them (it is possible to), you will only skim the surface of both places and not do a good job of either visit. And the logistics of travel is not easy.
My preference would be Segovia assuming you haven't been to either city before. Though, if your focus is to be immersed in religion and convents, choose Avila.
You can combine a visit to Segovia and Avila, from Madrid, in a day.
First go to Segovia, then to Avila
Start early from Madrid and budget to spend the first half of the day including lunch in Segovia.
When you reach Segovia, start your tour at the Roman Aqueduct, walk up to the Gothic Cathedral in the centre of town, and finish at the Alcazar of Segovia. Come back to the Aqueduct for lunch, there are many places with a nice atmosphere. You can walk throughout the town of Segovia with ease.
From Segovia, go to Avila.
See the main gates and churches in the walled city of Avila. If it is summer time, you can easily spend more time in Segovia so that you get to Avila when it is still light and stay for the lights to come on in the evening. The important thing in Avila is to see the lit up walls of the city.
Best transport combining Segovia and Avila
Bus from Madrid to Segovia: It is only an hour’s journey by train or bus; I suggest take the bus because it gets you to the centre of Segovia directly. If you take the high speed train from Chamartin, you will be dropped off at the station from where you need to take another bus to the centre of Segovia.
Bus from Segovia to Avila. This will take another hour and you should take the bus after lunch. It is convenient and fast.
Bus or train to return from Avila to Madrid. The 1 hour ride by bus is more convenient but you might encounter city traffic on the way back. The train ride from Avila is quite scenic but it will probably be dark so just chose whatever is easy for you.