Message Boards Message Boards

0
|
2019 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Exporting table of numbers in decimal format

Posted 10 months ago

In Mathematica 13, I have created a Table whose elements contain a list of three numbers. I want to export this list in a decimal format (i.e., without scientific notation). The output file should have three columns. The code is the following:

\[Nu][j_, \[Beta]_] := ((2 j + 1)*\[Pi])/\[Beta]
gbeta1 = 
 SetAccuracy[
  DecimalForm@
   Table[{\[Nu][j, 1.0], 0.0, -1.0/\[Nu][j, 1.0]}, {j, 0, 29999}], 16]

In the notebook the table looks nice, exaclty like I want to have it: three columns of numbers in decimal form with 16 digits after the comma.

However, when I export this table "gbeta1" as follows:

Export["Gimp_large1.dat", gbeta1]

then the exported becomes a mess instead of having a nice data file with 3 columns:

DecimalForm[{{3.14159265358979311599796346854418516159`16.497149872694134, 0``16., -0.31830988618379069121644420192751567811`15.502850127305866}, {9.42477796076937934799389040563255548477`16.974271127413797, 0``16., -0.1061032953945968970721480673091718927`15.025728872586203},...

What can I do to get a nice output file with three columns of number in decimal form?

Best

Georg

POSTED BY: Georg Rohringer
3 Replies

Does something like this help?

Export["Gimp_large2.dat", gbeta1[[1]] /. x_Real :> ToString@FortranForm@x, "CSV"]
POSTED BY: Ian Williams
Posted 10 months ago

Thanks, your suggestions works but there is still the problem that small numbers are represented in scientific notation (like 1e-6) in the output. However, I found today by myself another way which gives me exactly what I want:

gtabU0beta = 
 SetAccuracy[
  Table[{NumberForm[nu[j, 1.0], 
     ScientificNotationThreshold -> {-20, 20}], 
    NumberForm[0.0, ScientificNotationThreshold -> {-100, 100}], 
    NumberForm[-1.0/nu[j, 1.0], 
     ScientificNotationThreshold -> {-100, 100}]}, {j, 0, 29999}], 16]

So I use just the number form for my output and set a threshold for scientific notation. This gives me in the export file exactly what I need when exporting the data set as "Table".

POSTED BY: Georg Rohringer

Neat - I’ve not come across SetAccuracy before. Another useful nugget to stash away for future use.

POSTED BY: Ian Williams
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract