1
$\begingroup$

I hope you can help me with some questions about the format of the exported data.

I am using NIntegrate to calculate one integral that depends on a parameter x. I need to calculate this integral for many values of the parameter and export the results as an .xls file.

To do this I evaluate

Export["name.xls", Table[{x, f[x]}, {x, 0.05, 1.95, 0.1}]]

where f is the numerical integral.

When I open the resulting .xls file, all the numbers are like this:

{1.941691983316665*^-8}

Is it posible to eliminate the brakets in the result and also to write the number like something readable by Excel?, something like this maybe?

1.941691983316665E-8

Thank you for all your help!

As you might guess, editing by hand is not an option for so many values!

$\endgroup$
  • $\begingroup$ What happens if you try exporting as CSV? See e.g. ExportString[{{1., 1.235*^10}, {1.446, 1.9081*^-8}}, "CSV"] $\endgroup$ – J. M. will be back soon Mar 4 '18 at 17:03
  • 2
    $\begingroup$ that should not happen. Must be something wrong with your f which you haven't shown. (I'd guess f is returning a list, not just aa single number ) $\endgroup$ – george2079 Mar 4 '18 at 17:04
  • $\begingroup$ But I need to export both coordinates, x and f[x], it is posible to do this with ExportString? $\endgroup$ – Rafael Mar 4 '18 at 17:26
  • $\begingroup$ do this, evaluate f[.05] and look at the result. Do you get a number, or a number in { } braces? $\endgroup$ – george2079 Mar 4 '18 at 17:58
  • $\begingroup$ a number in braces.. $\endgroup$ – Rafael Mar 4 '18 at 18:07
1
$\begingroup$

I think it very easy to do what you ask. You only have to export your data as a .CSV file and open that file in Excel (or import it into Excel if you can't open it directly).

First make the data you want to export. Since you didn't provide a definition for f, I contrived my own function

f[x_] := NIntegrate[1.*^-5 u^-4, {u, 10, 10 + x}]

To make the data, evaluate

data = Table[{x, NIntegrate[1.*^-5 u^-4, {u, 10, 10 + x}]}, {x, 5}]
{{1, 8.28951*10^-10}, {2, 1.40432*10^-9}, {3, 1.81611*10^-9}, 
 {4, 2.11856*10^-9}, {5, 2.34568*10^-9}}

To export it, first define a path string by evaluating something similar to

 path = FileNameJoin[{$HomeDirectory, "Desktop", "data.csv"}];

I say similar because you may not want it on your desktop.

Now do the export.

Export[path, data]

Here is how the exported file looked when veiwed with OS X's Quick Look utility. Notice that Quick Look offers to open the file in Numbers, which is Apple's free spreadsheet app.

exported_csv

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.