function to combine individual mat files
Merging with Shabih's branch