I have a (n by m) matrix , in which the elements are recalculated and replaced by new ones in each iteration. (In other words I have a loop in which the elements of the mentioned matrix are being calculated and renewed in each step). What is the best way to save and export all the matrices?

So as an example:

  ne = 4
  ns = 6
  avec = Table[0, {ie, 1, ne}, {i, 1, ns}];
  Dat = Table[avec[[ie, i]] = ie + 1;
  anew = avec;
  Export[NotebookDirectory[] <> "avecexample.xls", anew]
  , {ie, 1, ne}, {i, 1, ns}]

but this one only exports the last avec. My first question is how to save all of them ? and in the next step, I want to know in case of more iterations , how to chose particular avecs to save (I mean for example how to save/export only the last five avecs calculated in the loop)?

  • 3
    $\begingroup$ Can you be more specific? To save data you can use Put, Export or DumpSave. But any strategy would depend on the details of your implementation. It's not fair if you ask us to guess what is your case. Please share a minimal working example of code and data in formatted form. How heavy is each matrix, how often will you need to save? $\endgroup$ – rhermans Jul 12 '19 at 16:32
  • 2
    $\begingroup$ Could you please give a bit of context? Maybe your idea of saving all matrices can be replaced by a better idea if you tell what you are ultimately trying to achieve. $\endgroup$ – Roman Jul 12 '19 at 16:50
  • $\begingroup$ I made some changes in the question, to make it more clear. $\endgroup$ – Delaram Nematollahi Jul 12 '19 at 19:53
  • 2
    $\begingroup$ Sow and Reap are typically used to store intermediate values and get them back at the end. See, e.g., mathematica.stackexchange.com/questions/181597/… $\endgroup$ – Sjoerd Smit Jul 12 '19 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.