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

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"

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");