Skip to main content
expanded question
Source Link
cormullion
  • 24.3k
  • 4
  • 64
  • 136

I used to do a lot of programming in R and recently switched to MathematicaMathematica. One thing that bothers me is that I haven't found a way to save variables, their values and definition!

Let's look at an example:

idx = Partition[RandomSample[Range[20], 20], 3];
Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, 
Length[idx]}];
Subscript[vars,{9,15,8}]
(*32*)

Is there a way to save the variable names as well as the corresponding values. And how would I read them into a new file? So that in a new file I can access with Subscript[vars,{9,15,8}] the value.

I tried it with Table[...]>>values.mx and read it in with values=<<values.mx but that only gives me the values, whereas I also need the definitions. I also tried it with DumpSave:

DumpSave["values.mx", 
 Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, Length[idx]}]]

but didn't get the syntax right and it didn't work. Help greatly appreciated!got an error

DumpSave::bsnosym: "Table[..] is not defined as a symbol or a context"

I used to do a lot of programming in R and recently switched to Mathematica. One thing that bothers me is that I haven't found a way to save variables, their values and definition!

Let's look at an example:

idx = Partition[RandomSample[Range[20], 20], 3];
Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, 
Length[idx]}];
Subscript[vars,{9,15,8}]
(*32*)

Is there a way to save the variable names as well as the corresponding values. And how would I read them into a new file? So that in a new file I can access with Subscript[vars,{9,15,8}] the value.

I tried it with Table[...]>>values.mx and read it in with values=<<values.mx but that only gives me the values, whereas I also need the definitions. I also tried it with DumpSave but didn't get the syntax right and it didn't work. Help greatly appreciated!

I used to do a lot of programming in R and recently switched to Mathematica. One thing that bothers me is that I haven't found a way to save variables, their values and definition!

Let's look at an example:

idx = Partition[RandomSample[Range[20], 20], 3];
Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, 
Length[idx]}];
Subscript[vars,{9,15,8}]
(*32*)

Is there a way to save the variable names as well as the corresponding values. And how would I read them into a new file? So that in a new file I can access with Subscript[vars,{9,15,8}] the value.

I tried it with Table[...]>>values.mx and read it in with values=<<values.mx but that only gives me the values, whereas I also need the definitions. I also tried:

DumpSave["values.mx", 
 Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, Length[idx]}]]

but got an error

DumpSave::bsnosym: "Table[..] is not defined as a symbol or a context"

Source Link
rainer
  • 401
  • 4
  • 12

Save variables values and definition

I used to do a lot of programming in R and recently switched to Mathematica. One thing that bothers me is that I haven't found a way to save variables, their values and definition!

Let's look at an example:

idx = Partition[RandomSample[Range[20], 20], 3];
Table[Subscript[vars, idx[[i]]] = Total[idx[[i]]], {i, 1, 
Length[idx]}];
Subscript[vars,{9,15,8}]
(*32*)

Is there a way to save the variable names as well as the corresponding values. And how would I read them into a new file? So that in a new file I can access with Subscript[vars,{9,15,8}] the value.

I tried it with Table[...]>>values.mx and read it in with values=<<values.mx but that only gives me the values, whereas I also need the definitions. I also tried it with DumpSave but didn't get the syntax right and it didn't work. Help greatly appreciated!