How to get a matrix into Matlab

Hello,

I have a bunch of matrices calculated for a specific problem and want to put them into Matlab for data analysis. I can already see them in the log file, but I want the individual matrices saved as their own files so I can mess around with them individually.

thanks for the help

$ cat matlab.edp
real[int, int] A(2, 2);
A = 1;
matrix sp = A;
load "PETSc"
Mat B(sp); // use your "matrix" here, sp is just a placeholder
ObjectView(B, format = "matlab", name = "first.m");
sp = 4 * sp;
Mat C(sp); // use another "matrix" here, sp is just a placeholder
ObjectView(C, format = "matlab", name = "second.m");
$ ff-mpirun -n 1 matlab.edp -v 0 && cat first.m && cat second.m
[...]
%Mat Object: 1 MPI processes
%  type: mpiaij
% Size = 2 2
% Nonzeros = 4
zzz = zeros(4,3);
zzz = [
1 1  1.0000000000000000e+00
1 2  1.0000000000000000e+00
2 1  1.0000000000000000e+00
2 2  1.0000000000000000e+00
];
 Mat_0x84000000_0 = spconvert(zzz);
%Mat Object: 1 MPI processes
%  type: mpiaij
% Size = 2 2
% Nonzeros = 4
zzz = zeros(4,3);
zzz = [
1 1  4.0000000000000000e+00
1 2  4.0000000000000000e+00
2 1  4.0000000000000000e+00
2 2  4.0000000000000000e+00
];
 Mat_0x84000000_1 = spconvert(zzz);

(1) Use ‘ofstream’ to write the FreeFEM matrices as text files. Then read the text file in MATLAB to form the matrix using the row and column index and the corresponding value.

(2) https://github.com/samplemaker/freefem_matlab_octave_plot

(3) https://www.mathworks.com/matlabcentral/fileexchange/26833-freefem-to-matlab

(4) https://www.um.es/freefem/ff++/uploads/Main/FFmatrix_fread.m