Take the 2-minute tour ×

This question already has an answer here:

I have a function with two variables:

f[x_,y_]:=f[x,y] = ...

I calculated some values (they are fractions like 435345345/3424242424) and would like to store the values from x=1 to x=5000 with y=0 in a file, so that I can use them later again in a function g[x]

I exported them:

Export["file.dat", Table[f[x,0],{x,1,5000}]

And then I import them in another file:

data = Import["file.dat", "List"]

Now I can access the fractions in data by using, for example:


Which gives me the fraction that was originally stored in f[7,0]

So far so good, but I would again like to have the values stored in some function g, with the properties that (in new file) g[x] = f[x,0] (in old file) for x between 1 and 5000

I am not really sure how the notation for that would be :-(

Thank you for your help.

share|improve this question
Have a look at DumpSave. –  b.gatessucks Feb 19 '13 at 10:23
add comment

marked as duplicate by Mr.Wizard Feb 21 '13 at 15:17


1 Answer

up vote 3 down vote accepted

You are looking for Save or DumpSave

Here is an example:

(*Put some definitions into f*)
f[x_, y_] := f[x, y] = x + y;
Table[f[x, y], {x, 0, 10}, {y, 0, 10}];

(*are the definitions there?*)

(*Save to file*)
Save["f.m", f]

(*Clear all definitions and check that none remain*)

(*Import again*)

share|improve this answer
Thank you for your response. How would I save only a specific part of when doing Save["f.m", f], because all data might be big (because the amount of ram mathematica is using after storing the values is 100gb) - I only need f[1,0] to f[5000,0], which is like 40mb when exporting it as a list. –  user5988 Feb 19 '13 at 11:04
you can unset the rest as per this question mathematica.stackexchange.com/questions/71/… –  Ajasja Feb 19 '13 at 11:27
(clicked too early, 1 sec..) –  user5988 Feb 19 '13 at 12:19
I did it by basically doing it the other way around, by creating, saving and importing a new function g with just the needed values: For[i = 1, i <= 5000, i++, g[i] = f[i, 0]] -- Save["g.m",g] -- Import[g] That worked, thanks again :-) –  user5988 Feb 19 '13 at 12:36
You're welcome. –  Ajasja Feb 19 '13 at 12:37
add comment
