1
$\begingroup$

I have this table:

data = Table[{x, y, Sqrt[r^2-x^2-y^2]-r+RandomReal[{0,0.005}]}, {x, 0, 2.5,0.5}, {y, 0, 2.5,0.5}];

How can I export it to a .txt file using Wolfram Cloud? Preferably in such a way that I can import it back and do further manipulations if I need to.

$\endgroup$
  • $\begingroup$ Is it essential that you have it as a TXT file or do you simply want to be able to export it and then re-import it? If you are just looking to have it cloud accessible, you simply have to use CloudPut and CloudGet. $\endgroup$ – kickert Sep 23 '19 at 13:44
  • $\begingroup$ A txt file would be preferable so I can use the data in other softwares as well. $\endgroup$ – Rodrigo Sep 23 '19 at 13:51
  • $\begingroup$ One issue you might run into is how Mathematica notates square roots. The cleanest approach might be to export it to a local TXT then copy that file to the cloud: CopyFile[Export["data.txt", data], CloudObject["data.txt"]]. Then bring it back in: ToExpression@ Import["https://www.wolframcloud.com/obj/YOUR.NAME/data.txt"] $\endgroup$ – kickert Sep 23 '19 at 14:16
2
$\begingroup$

As already suggested above, using Export followed by CopyFile to a CloudObject certainly works.

You can also Export directly to a CloudObject, or (even more concisely) use CloudExport. In terms of the format, you might consider "CVS" instead of "TXT". Then this would become:

CloudExport[data, "CSV", "data.csv"]

To bring it back into WL, you would use CloudImport["data.csv"]. The entries in the table will be raw strings, so you could apply ToExpression to them to turn them into WL expressions. You should only do that if you trust the data, though, since it would execute arbitrary expressions. The third argument to ToExpression could be useful, where you could provide Hold to avoid immediate evaluation of each item.

If you're only dealing with "simple enough" expressions, you could also use Interpreter["Expression"], which allows evaluation of simple expressions but does not allow other side effects such as accessing the file system (see the Expression interpreter type documentation for more details). So you would use

Map[Interpreter["Expression"], CloudImport["data.csv"], {2}]

to turn each entry in the two-dimensional table into an expression.

$\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.