0
$\begingroup$

Continuation of this question: How to export if I need to have two extensions instead of one. E.g., in the previous case one can generate lists labeled L[1], L[2],.....and so on using a loop. But if I have 2 loops and hence two variables and the lists are labeled L[1,1], L[1,2],… then L[2,1], L[2,2],… How do I export them in wdx format?

$\endgroup$

2 Answers 2

2
$\begingroup$

Make some 2D data:

data = RandomInteger[Range@2, {5, 3}];

Create a series of strings to represent the indices of the elements of data:

Array[ToString[#1] <> "_" <> ToString[#2] &, Dimensions@data]

{{"1_1", "1_2", "1_3"}, {"2_1", "2_2", "2_3"}, {"3_1", "3_2", "3_3"}, {"4_1", "4_2", "4_3"}, {"5_1", "5_2", "5_3"}}

Then just add those strings into whatever basename and extension you are using for your files and use that with Save, DumpSave or Export.

$\endgroup$
2
  • $\begingroup$ Since you used Dimensions, perhaps StringJoin[Riffle[ToString/@{##}, "_"]]& would be more universal. $\endgroup$
    – VF1
    Dec 15, 2012 at 5:43
  • $\begingroup$ @VF1 That looks significantly different enough to be an answer :) $\endgroup$ Dec 15, 2012 at 10:31
2
$\begingroup$

If you have n-dimensional data, then create the names:

names = Array[StringJoin[Riffle[ToString/@{##}, "_"]]&, Dimensions[data]]

Then export each one:

MapThread[Export[#1 <> ".wdx", #2] &, {names, data}, Depth@data - 1]
$\endgroup$

Your Answer

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

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