added .mat writing