Question: How to import/generate a file of numerous matrices?

I want to analyze the runtimes on certain Linear Algebra functions in Maple, so I need a (large) set of matrices to input into these functions.

I have written the below code, which does succesfully generate a file of matrices:

for i from 0 to 10 do
resultsFile := "C:\\matrices";
matrix1 := RandomMatrix(3, 3, generator = -10 .. 10);
fprintf(resultsFile, "%a\n", matrix1);
end do

The resulting file looks like:

Matrix(3, 3, [[9,1,-4],[-5,6,-10],[-10,-4,-4]])
Matrix(3, 3, [[-2,8,5],[-6,-10,3],[9,8,-6]])
Matrix(3, 3, [[6,4,-2],[4,-10,7],[-6,-2,10]])

However, I am unable to read the matrices from this file back into Maple. When using the code below, I get an error.

input := "C:\\matrices";
matrix1 := fscanf(input, "%a");
Error, (in fscanf) incorrect syntax in parse: `;` unexpected (near 10th character of parsed string)

I think the error is that %a in fscanf scans up to the next whitespace, so the spacing in Matrix(3, 3, [[9,1,-4],[-5,6,-10],[-10,-4,-4]]) is throwing fscanf off. Do you guys know of any way I can fix this?


Or, is there a better way for me to generate these matrices so that they can be easily read into Maple? I've considered using ImportMatrix/ExportMatrix, but I believe that they only work for a single matrix, not the numerous ones that I would need. 

Please Wait...