transfer array to matrix and save matrix to file before calculating