2
$\begingroup$

This answer to this question, teaches us how to export the result of NDSolve to an Excel file. It is easyly adapted to the case I want a .txt file:

Export["c:\\test.txt", Table[Flatten[{t, hf[t], hs[t]} /. sol1], {t, 0, 100}]]

But in this way the file has unwanted parenthesis {} in every row:

{0, 20., 0.}
{1, 19.80198672353379, 0.19801327646620656}
{2, 19.607894374473258, 0.3921056255267404}
{3, 19.41764531409662, 0.5823546859033791}
[...]

How do I remove the {}? I tried playng with Flatten, but it doesn't work.

$\endgroup$
  • 2
    $\begingroup$ Try to play with the export format (see export documentation). For example Export["c:\\test.txt", Table[Flatten[{t, hf[t], hs[t]} /. sol1], {t, 0, 100}],"Table"] does the trick. However, ".txt" does not accept some format (e.g. "Data"), but you can use .dat instead for example $\endgroup$ – Fraccalo May 20 '18 at 19:58
  • $\begingroup$ If it’s only a few files you can use find and replace all in notepad. $\endgroup$ – Vsevolod A. May 20 '18 at 22:52
  • 1
    $\begingroup$ Don't export as .txt. Export as .csv $\endgroup$ – m_goldberg May 21 '18 at 0:50
2
$\begingroup$

Try Export["c:\\test.txt", Table[Flatten[{t, hf[t], hs[t]} /. sol1], {t, 0, 100}],"Table"]?

$\endgroup$
  • $\begingroup$ I would use "CSV", but "Table" should also work fine here. $\endgroup$ – GenericAccountName May 22 '18 at 18:54

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.