Hello and welcome to the forum!
There is no direct train from Malaga to Cadiz...I went many times to Cadiz (Puerto de Santa Maria) in the past every weekend, and I had to take a train to Seville (Dos Hermanas is the best option as it is the train station just before "Santa Justa" which is the last one), and from Seville you have to take another train to Cadiz which is the last train stop as far as I remember.
My recommendation...why not renting a car in Malaga?. Train ticket is expensive and the travel trip can take around 5 hours or more while by car you can be in Cadiz
in about 2 hours and a half.