Please see the documentation and in particular the example shown in https://www.mathworks.com/help/signal/ref/spectrogram.html
One you attempt to code something up please come back if you have any specific issues implementing this for your situation.