Lets say I have a list of undefined variables {a1,a2,a3,a4}
. I could type out each element by hand, but if I wanted to eventually extend the list, it would be easier generate the list by Table[ToExpression["a" <> ToString[i]], {i, 1, 4}]
.
Now, lets say I want to assign values to each element. In the first method when I type it out by hand, I simply put {a1,a2,a3,a4} = {1,2,3,4}
, then I get the result that I wanted: a1=1, a2=2, a3=3, a4=4.
Now, if I try to assign to each element a value using the second method, I would think it would make sense to put Table[ToExpression["a" <> ToString[i]], {i, 1, 4}] = {1,2,3,4}
. However, it gives me an error.
How can I equate a variable list generated by the table function to another list? I have tried about 5 different methods, and the only thing that seems to work is to copy and paste the output from the table function into a new kernel, but this is not an elegant solution at all.
Indexed
cannot meet your needs? $\endgroup$