How to read complex matrix in matlab

I am writing a complex matrix using ofstream in FreeFEM++

`ofstream file("A.dat");
           file << A <<endl;

And I am trying to read it in MATLAB using dlmread but it causes error.
Can someone suggest a better way to write the complex matrix and read it in MATLAB

load "PETSc-complex"
Mat<complex> dump(A);
ObjectView(dump, format = "matlab", name = "A.dat");
1 Like

Can you tell how to read this file in MATLAB ?
thanks

Sorry, the file extension should be .m, then simply type the file name (without the extension) in MATLAB.

Earlier I used this method to save the matrix, but for my current case when i try to run the file in MATLAB i get the message " File is too large for MATLAB to run"

That’s a matlab issue, not a freefem one. If you’re using this for eigenvalue calculations, you should just use SLEPc directly.

What Chris says. The likelihood that MATLAB can do something that PETSc or SLEPc can’t is very slim. But if you insist on reading large files in MATLAB (which itself is a rather bad idea), you could do the following.

load "PETSc-complex"
Mat<complex> dump(A);
ObjectView(dump, format = "binary", name = "A.dat");

In MATLAB, use share/petsc/matlab/PetscBinaryRead.m · main · PETSc / petsc · GitLab and do:

A = PetscBinaryRead('A.dat', 'complex', true);