func to write mats, more iterations for time testing