0
$\begingroup$

I want to export my_data and then import them back again in exactly the same data structure as the one they had when they were initially generated.

mydata = Table[{σ, RandomVariate[NormalDistribution[0, σ]]}, {σ, 1, 2}, {100}]

I say exactly, because no matter what I have tried based on the online documentation, when I import the exported data, the structure is not valid for plotting them using:

Show[
 Histogram3D[
  mydata,
  PlotRange -> {{0, 10}, {-20, 20}, {0, All}},
  AxesLabel -> (Text[Style[#, Italic, 14]] & /@ {"a", "b", "c"})]
 ]

(plotting works with the initially generated data)

Could you provide here with the correct export and import commands?

$\endgroup$
  • $\begingroup$ Underscore should not appear in a Mathematica symbol. Use mydata instead of my_data. $\endgroup$ – Jean-Pierre Oct 4 '20 at 15:18
  • $\begingroup$ Thanks for mentioning. Though in practice I am not using. The variable is simply "data". Hence, the question still holds. $\endgroup$ – Gouz Oct 4 '20 at 15:21
1
$\begingroup$

You can use Put (>>) and Get (<<).

mydata>>filename
mydataImported = <<filename
$\endgroup$
0
$\begingroup$

Alternatively, exporting and importing as a spreadsheet

Clear["Global`*"]

SeedRandom[1234]

Generating and exporting the data

Export["/Users/roberthanlon/Downloads/mydata.xls",
  mydata = Table[{σ, 
     RandomVariate[NormalDistribution[0, σ]]}, {σ, 1, 2}, {100}]];

The imported data is

mydata2 = Import["/Users/roberthanlon/Downloads/mydata.xls"];

The data is equivalent

mydata == mydata2

(* True *)

Although not identical

mydata === mydata2

(* False *)

Generating the histograms

{hg1, hg2} = 
 Show[Histogram3D[#, PlotRange -> {{0, 10}, {-20, 20}, {0, All}}, 
     AxesLabel -> (Text[Style[#, Italic, 14]] & /@ {"a", "b", 
         "c"})]] & /@ {mydata, mydata2}

enter image description here

The histograms are identical

SameQ @@ {hg1, hg2}

(* True *)
$\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.