TransWikia.com

Exported Excel File - decimals

Mathematica Asked on May 9, 2021

Im trying to export data from the interpolating function result to excel.

everything works fine and the plots are as expected, but if I want to export these data to excel using

Export["data.xlsx", Table[Flatten[{t, soldata}], {t, 0, tmax}]]

the t values only show 1 decimal whereas the soldata results are expressed in much as 15 decimals. This makes the exported file missing many cells. How can I make t in the excel file export as much decimals.

Here is the last part of the code

sol = ParametricNDSolveValue[{eqns, init}, vars, {t, 0, 2}, {p}]

soldata = Evaluate[sol[100][[1]], sol[100][[2]]]

excelData = Table[Flatten[{t, soldata}], {t, 0, 2}]

Export["data.xlsx", excelData]

One Answer

From the question, I still don't understand what soldata is. Can I assume it's a 2D array? If this is wrong, please add the output of soldata[[1;;2] to the question.

Assuming soldata has 2 columns, and row 1 represents t = 0, and the last row represents t = tmax. Here are some random values.

SeedRandom[123]
(*assume a 2D array, 5 rows by 2 columns*)
soldata = RandomReal[1, {5, 2}];

Let's add the time values from 0 to tmax as the first column of the Excel data.

tmax = 2;
excelData = 
  Prepend[##] & @@@ 
   Transpose[{soldata, N@Subdivide[0, tmax, Length@soldata - 1]}];

Or another method,

tmax = 2;
elcelData = Flatten /@ 
  Transpose[{N@Subdivide[0, tmax, Length@soldata - 1], soldata}];

So soldata:

${smallleft( begin{array}{cc} 0.455719 & 0.977826 0.943215 & 0.962216 0.302348 & 0.466709 0.0616383 & 0.385645 0.429838 & 0.778744 end{array} right)}$

becomes excelData:

${smallleft( begin{array}{ccc} 0. & 0.455719 & 0.977826 0.5 & 0.943215 & 0.962216 1. & 0.302348 & 0.466709 1.5 & 0.0616383 & 0.385645 2. & 0.429838 & 0.778744 end{array} right)}$

Export excelData to an Excel spreadsheet.

Export["data.xlsx", excelData]

Does excelData create the correct spreadsheet?

Answered by creidhne on May 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP