0

Now, I want to assign some values for a Table list and I find that

If

 {mat[1], mat[2], mat[3], mat[4], mat[5]}={4,23,3,12,1};

it is no problem. But, if we use

  Table[mat[n],{n,1,5}]={4,23,3,12,1};

It doesn't work. Why ? Thanks.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Orders
  • 1,247
  • 11
  • 20

2 Answers2

1

You should evaluate the left-hand side first.

Evaluate[Table[mat[n], {n, 5}]] = {4, 23, 3, 12, 1}

Another possible way:

With[{values = {4, 23, 3, 12, 1}},
 Do[mat[n] = values[[n]], {n, 5}]]
BoLe
  • 5,819
  • 15
  • 33
0

You must tell the kernel to evaluate the left hand side before invoking Set Try this:

Evaluate[Table[mat[n],{n,1,5}]]={4,23,3,12,1};
Jason B.
  • 68,381
  • 3
  • 139
  • 286