# Automatic assignment of variables?

**URL:** <https://community.wolfram.com/t/automatic-assignment-of-variables/9027>\
**Category:** Questions\
**Created:** [August 9, 2016, 12:09pm UTC](https://community.wolfram.com/t/automatic-assignment-of-variables/9027 "2016-08-09T12:09:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ulrichutiger](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ulrichutiger/32/40153_2.png) [@ulrichutiger](https://community.wolfram.com/u/ulrichutiger)\
**Post date:** [August 9, 2016, 12:09pm UTC](https://community.wolfram.com/t/automatic-assignment-of-variables/9027/1 "2016-08-09T12:09:17Z")

</div>

I would like to assign a value to a automatically created symbol. Let’s say to bij where i and j are integers. I know I could do this with this code:

```
Do[b[i, j] = f[i, j], {i, n}, {j, n}];

```

But I prefer bij instead of b[i,j] because the code is shorter and becomes more readable. The problem is that with something like

```
 i = 1; j = 1;
   StringJoin["b", ToString[i], ToString[j]] = 2

```

or

```
 Symbol[StringJoin["b", ToString[i], ToString[j]]] = 2

```

or

```
ToExpression[StringJoin["b", ToString[i], ToString[j]]] = 2

```

one gets always the same error and the value 2 is not assigned to b11 in this case. So how can this be achieved?

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [August 9, 2016, 12:35pm UTC](https://community.wolfram.com/t/automatic-assignment-of-variables/9027/2 "2016-08-09T12:35:58Z")

</div>

In[3]:= Evaluate[  
ToExpression[StringJoin[“b”, ToString[i], ToString[j]]]] = 2;

```
In[4]:= bij

Out[4]= 2

```

---

<div class="post-metadata">

**Author:** ![ulrichutiger](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ulrichutiger/32/40153_2.png) [@ulrichutiger](https://community.wolfram.com/u/ulrichutiger)\
**Post date:** [August 9, 2016, 2:53pm UTC](https://community.wolfram.com/t/automatic-assignment-of-variables/9027/3 "2016-08-09T14:53:42Z")

</div>

This works, thanks.
