You can reach Matera by train getting off at Ferrandina Scalo (on Trenitalia webpage "Ferrandina-Pomarico-Miglionico"). From there you can take a shuttle bus.
Alternatively you can get off at Potenza (coming from North) or Metaponto (coming from South) and take a bus from there.