Suppose I have 20 Matrices: Mat[1], Mat[2],...,Mat[20]. What is the best way to export (and Import) this set of Matrices in a file? How can I do that? (may be any format, for example: csv). Thanks.


closed as off-topic by MarcoB, Carl Lange, m_goldberg, bbgodfrey, Alex Trounev Mar 12 at 21:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Carl Lange, bbgodfrey, Alex Trounev
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Have you seen Export? If CSV works, then that's probably a pretty good choice of a text only format that is widely interoperable. Otherwise you could consider perhaps the HDF5 file format. $\endgroup$ – MarcoB Mar 6 at 22:18
  • $\begingroup$ Yes, but how the command is constructed to consider a set and not only one matrix? If I Export and Import, how could be the commands? $\endgroup$ – J.R.Descardeci Mar 6 at 22:31
  • 1
    $\begingroup$ If your only need is to re-import into Mathematica, you can use DumpSave to save the definitions in a .mx file. They can then be imported using Get ( << ). $\endgroup$ – David Keith Mar 6 at 22:43
  • 1
    $\begingroup$ Are you looking for 20 separate files or a single file with all 20 matrices? $\endgroup$ – MassDefect Mar 6 at 22:45
  • $\begingroup$ Just one file. Severral files is easy to do. $\endgroup$ – J.R.Descardeci Mar 7 at 11:44

You can use the Export to save the set of objects. Let's say we have ten 2x2 matrices inside a:


Make an exporting function ef and sequentaly apply it for elements of a:

SetDirectory["your path"];

It will give you ten dat-files with 2x2 matrices.

Of course, the simpler way is to export a as one file:

Export["file.dat", a]


  • $\begingroup$ Thanks a lot. Very helpfull. Very clever. $\endgroup$ – J.R.Descardeci Mar 7 at 11:46

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