4
$\begingroup$

This is probably an easy question: I am exporting the results from a longer calculation into a dat-File, then I set the cell to non-evaluatable and put an Import in front, so I can later work with the results, even after closing and reopening the notebook:

results = Import["results.dat"]

(non-evaluatable) results = makeLongCalculation[parameters]
(non-evaluatable) Export["results.dat",results]

doSomethingwithResults[results]

(Is there a more elegant way?)

Now, I have the problem that complex numbers are imported as strings. My results are typically of the form {{0.01,3*10^-6+5*10^-4*I},...}. Is there any more straightforward way than to apply something like ToExpression to the Import? I feel that native Mathemat

$\endgroup$
1
  • 1
    $\begingroup$ I think you accidentally the sente... ;) Also, it sounds like you need NumberForm $\endgroup$
    – rm -rf
    Commented Jul 11, 2012 at 8:59

2 Answers 2

4
$\begingroup$

Or in concise notation:

results >>   "results.dat";
results = << "results.dat";

You can automate the process slightly, by reading the data in if the file exists and results isn't defined or writing it out otherwise.

If[Head@results === Symbol && FileExistsQ["complex.dat"], 
 results = << "complex.dat", results >> "complex.dat"]
$\endgroup$
3
  • $\begingroup$ As I would like to maintain control (calculation may take8h on 8cores), I will not use the automation here, but nevertheless nice idea. Thanks. (Also to Simon.) $\endgroup$
    – mcandril
    Commented Jul 11, 2012 at 10:06
  • $\begingroup$ @mcandril Thanks, it may be that someone here can reduce that computation time for you. $\endgroup$ Commented Jul 11, 2012 at 14:45
  • $\begingroup$ It is basically just adding up A LOT of complex numbers, for unaproximated Frenel-Huygens principle. I am not sure how much optimisation potential there is and how to pose the question so its relevant. $\endgroup$
    – mcandril
    Commented Jul 12, 2012 at 15:54
5
$\begingroup$

You could use Put and Get instead of Export and Import.

Put[results,"results.dat"]
results = Get["results.dat"];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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