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"
DumpSave[ ]
not work properly for you? $\endgroup$DumpSave[]
. Can you help him? $\endgroup$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"*)
$\endgroup$Subscript[vars,i]
is not the easy way to do indexing in Mathematica. It is more of a typesetting convenience, that is, for display. The easy thing to do is to havevars
be a list, and to index into that list. This is the way I answered the question below. $\endgroup$DumpSave
. $\endgroup$