# Exported Excel File - decimals

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]

• Please give a description of soldata. Is it a list? Is it a 2-dimensional array where each row is a list of values? If soldata is a 2D array, is there a row for each of 0 to tmax? – creidhne Nov 12 '20 at 23:52
• Maybe excelData = Table[Flatten[{t, soldata}], {t, 0, 2, 0.001} – Bill Watts Nov 14 '20 at 0:13
• I still don’t the dimensions and content of soldata, but from your edit, I assume soldata is a 2D array with 2 columns, and rows for t = 0, to t = tmax. Do you want column 1 of the Excel data to be values equally spaced between 0 and tmax? I’ll assume... I’ve replaced my answer. – creidhne Nov 14 '20 at 0:54
• {t, 0, 2, 0.001} did the job. I don't know why when I tried this before, It did not work. Its a very simple solution but I missed it. My bad. Thanks everyone – MSM Nov 14 '20 at 1:18

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:

$${\small\left( \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:

$${\small\left( \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?

• Maybe I was misunderstood and my question wasn't clear. I edited the question and added an image of what I am missing – MSM Nov 13 '20 at 22:57
• Thank you creidhne for your effort in answering. It was a simple solution and was my bad missing it. I appreciate your answer nonetheless. – MSM Nov 14 '20 at 1:20