# The best way to export a set of n matrices [closed]

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 TrounevMar 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.

• 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. – MarcoB Mar 6 at 22:18
• 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? – J.R.Descardeci Mar 6 at 22:31
• 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 ( << ). – David Keith Mar 6 at 22:43
• Are you looking for 20 separate files or a single file with all 20 matrices? – MassDefect Mar 6 at 22:45
• Just one file. Severral files is easy to do. – 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:

a=Table[{{i,0},{0,i}},{i,10}];


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

SetDirectory["your path"];
ef=Export[ToString[#[[1,1]]]<>".dat",#]&
ef/@a


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]


or

DumpSave["file.mx",a]

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