Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to write a program which will generate a list of objects and then exports it in a separate file and clears its memory. As an example I tried the following

Do[{Subscript[l, p] = Table[Subscript[l, p, i], {i, 10}];
  Export["\!\(\*SubscriptBox[\"l\", \"p\"]\).mnaz", 
   Compress[Subscript[l, p]], "String"]; Clear[Subscript[l, p]]}, {p, 
  1, 3}]

Of course, the above is just a sample (and my actual list(s) are more bulky (actually they are list of matrices)), but I hope it explains the spirit. I wanted to export each list separately so that I can get separate files like l_1.mnaz, l_2.mnaz etc., which I can import again by using the same type of code.

Motivation: I need to actually generate a huge list of data. However whatever I do, my system goes out of memory after 5000 loops, which itself takes a lot of time. One reason is that, I need to modify the list at each loop. It seems 1000 loops takes a reasonable time. Hence I am trying to break the loop into smaller chunks, export the data, and clear the memory for the next loop. Clear[Subscript[l, p]] is used for that purpose.

share|improve this question
Subscripts don't work in any filename system I know of, so I think that will cause problems. –  Verbeia Jul 29 '12 at 9:11
@Verbeia even if they did "\!\(\*SubscriptBox[\"l\", \"p\"]\).mnaz" would not work. One could instead use: ToString[Subscript[l, p], TeXForm] <> ".mnaz" or if the file system supports it something besides TeXForm. –  Mr.Wizard Jul 29 '12 at 9:25
add comment

1 Answer

up vote 7 down vote accepted

Try this:

 l[p] = Table[Subscript[l, p, i], {i, 10}];
 Export["l_" <> ToString[p] <> ".mnaz", Compress@ l[p], "String"];
 l[p] =.
 , {p, 1, 3}

I replaced Subscript[l, p] with l[p]. Frankly I don't see a reason to not simply use temp = Table[ . . . but I am trying to keep to the spirit of your example.

share|improve this answer
Beat me to it by seconds! –  Verbeia Jul 29 '12 at 9:12
@Verbeia I'm trying to defend my rank against the Hypno-Toad onslaught. :o) –  Mr.Wizard Jul 29 '12 at 9:16
Hey! I need two votes for keeping Mr awake all night –  belisarius Jul 29 '12 at 9:40
@belisarius What's this? Are you colluding with the green one? ;-p –  Mr.Wizard Jul 29 '12 at 9:56
@Mr.Wizard that is just the spirit ;-) –  Yves Klett Jul 29 '12 at 9:58
show 3 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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