read and write external mat files