I am new to this newsgroup and to Matlab programming.
Can anyone tell me how Matlab write a complex number or
matrix to a file?
So far this is what i have:
A = (.....complex matrix);
fid = fopen('value.bin','wb');
fwrite(fid,A);
This code allow me to write "A" to a file, but I don't
know how to read it.
Basically, I want to write "A" to a file, then this file
will be read by a c++ application.
Thank you
Matlab strips off the complex portion of any value before fwrite().
You will therefore have to write the real and imaginary portions
seperately.
For example,
U = [1+2*i,3+4*i];
t=fopen('/tmp/foo','w');
fwrite(t,[real(U);imag(U)],'float64','n');
fclose(t);
!od -t fD /tmp/foo
0000000 1.000000000000000e+00 2.000000000000000e+00
0000020 3.000000000000000e+00 4.000000000000000e+00
Note here that I used ';' between the real() and imag(). I
was taking advantage of the fact that fwrite writes down columns
to cause it to write each value as a (real,imaginary) pair .
By the way, in Matlab, you do *not* use the 'b' suffix when
opening a file for binary writing -- instead you use a 't' suffix
when opening a file for text.
--
"Prevention is the daughter of intelligence."
-- Sir Walter Raleigh