I have previously been using
logf[x_, y_] := f[x, y] /. v_ :>(PutAppend[Unevaluated[f[x, y] = v;], "out.txt"];);
which produces output like f[1,5]=2.566665345435;
on each line of the output file. How could I modify this to produce CSV file, i.e. output lines that look like
1, 5, 2.5666665345435
3, 4, 4.4353453453453
.
.
I tried the obvious guess
logf[x_, y_] := f[x, y] /. v_ :>(PutAppend[Unevaluated[x, y, v], "out.txt"];);
but this does not work, as the word "Sequence" also gets exported.
Also is this the best way I can export data from Mathematica to be read in by c++ code or is there a better way?
f[1,2]=2.3+9.8I
. The c++ code needs to read this in and then I basically want to store in some object that resembles a function (I was thinking of usingmap
with x,y as a key and the complex value of the function at (x,y) as the value but maybe there is a better way). There is no necessity for the file to be human readable, but it could be read on other computers. $\endgroup$OpenWrite
orOpenAppend
,BinaryWrite
andClose
. WithBinaryWrite
you can store numeric data as reals of various bitlengths or even as complexes. For details you might want to search those functions andBinaryRead
in the documentation. It should be relatively easy and very efficient to read these files from c++. As long as the "endianness" is the same it shouldn't be a problem to read those files on another computer... $\endgroup$