code for generating mat from text files