I'm having issues while exporting a tables of numerical values to "*.dat" data files.
Here's the thing, sometimes when I export a table, I get more decimals on some random values. The problem is that they weren't even there in the first place.
Now, for the sake of illustration, here's a very simple example on the issue. I tried constructing the following table :
Table[t, {t, 0, 0.4, 0.1}]
Which provides with the following list :
{0., 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, \
0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, \
0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, \
0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4}
Now, I just tried to export it using the Export
command like this :
Export["t.dat", Table[t, {t, 0, 0.4, 0.1}], "Table"]
and everything should be fine, but when you try to read what's in "t.dat" using FilePrint
:
FilePrint["t.dat"]
I get the following :
0. 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35000000000000003 0.36 0.37 0.38 0.39 0.4
Note that the number 0.35 suddenly became 0.35000000000000003, which messes everything up. Is there something to solve this issue? I tried using the NumberForm
function but it changes the structure of the exported list...
What I intend to do is to export t list presented above, alongside with another list in which I do operations using the values of the first one. For example :
time = Table[NumberForm[i, 6], {i, 0, 0.2, 0.01}];
op = Table[time[[i]]^2 + time[[i]], {i, 1, Length@time}];
Export["data.dat",Transpose@{time,op}, "Table"];
FilePrint["data.dat"];
Which returns :
0. NumberForm[0., 6] + NumberForm[0., 6]^2
0.01 NumberForm[0.01, 6] + NumberForm[0.01, 6]^2
0.02 NumberForm[0.02, 6] + NumberForm[0.02, 6]^2
0.03 NumberForm[0.03, 6] + NumberForm[0.03, 6]^2
0.04 NumberForm[0.04, 6] + NumberForm[0.04, 6]^2
0.05 NumberForm[0.05, 6] + NumberForm[0.05, 6]^2
0.06 NumberForm[0.06, 6] + NumberForm[0.06, 6]^2
0.07 NumberForm[0.07, 6] + NumberForm[0.07, 6]^2
0.08 NumberForm[0.08, 6] + NumberForm[0.08, 6]^2
0.09 NumberForm[0.09, 6] + NumberForm[0.09, 6]^2
0.1 NumberForm[0.1, 6] + NumberForm[0.1, 6]^2
0.11 NumberForm[0.11, 6] + NumberForm[0.11, 6]^2
0.12 NumberForm[0.12, 6] + NumberForm[0.12, 6]^2
0.13 NumberForm[0.13, 6] + NumberForm[0.13, 6]^2
0.14 NumberForm[0.14, 6] + NumberForm[0.14, 6]^2
0.15 NumberForm[0.15, 6] + NumberForm[0.15, 6]^2
0.16 NumberForm[0.16, 6] + NumberForm[0.16, 6]^2
0.17 NumberForm[0.17, 6] + NumberForm[0.17, 6]^2
0.18 NumberForm[0.18, 6] + NumberForm[0.18, 6]^2
0.19 NumberForm[0.19, 6] + NumberForm[0.19, 6]^2
What I mean by "changes its structure" is the fact that I can no longer operate on the time list and its values correctly...