FREAD and FWRITE both support the native ANSI C data types. There are no ANSI C data types that correspond to complex values. Hence, there is no precision for complex numbers.
As a workaround you could do something like the following and store areal and aimag in separate parts of your binary data file.
areal = real(a);
aimag = imag(a);
You also need to know the precision of your file before you can use FREAD, otherwise you will get incorrect results.
The following is an example of how to read and write complex data into a binary file from MATLAB.
z=complex(rand(5),rand(5));
disp('The following are the REAL components:')
a=real(z)
disp('The following are the IMAGINARY components:')
b=imag(z)
[r,c]=size(z);
z1=[];
for cc=1:c
z1=[z1 a(:,cc) b(:,cc)];
end
disp(sprintf(['The following is 1 column of REAL components and then next \n' ...
'to it on the right is 1 column of IMAGINARY components (and then repeated):']))
z1
fid=fopen('testdata1','w');
fwrite(fid,z1,'double');
fclose(fid);
disp('The following is the same as z1 (c1=z1) AS READ FROM THE BINARY FILE')
fid=fopen('testdata1','r');
c1=fread(fid,[r,2*c],'double')
fclose(fid);
Here is another way to output the data.
disp(sprintf(['The following is 5 columns of REAL components and then next \n' ...
'to it on the right are 5 columns of IMAGINARY components:']))
z2=[a b]
fid=fopen('testdata2','w');
fwrite(fid,z2,'double');
fclose(fid);
disp('The following is the same as z1 (c2=z1) AS READ FROM THE BINARY FILE')
fid=fopen('testdata2','r');
c2=fread(fid,[r,2*c],'double')
fclose(fid);