0
$\begingroup$

I want to generate a table that gives the following output:

output: {"x1", "x2", "x3", "x4", "x5"}

I have tried:

Table["x"*i, {i, 5}] 

which gives

{"x", 2 "x", 3 "x", 4 "x", 5 "x"}

I wonder what is a correct way of doing this?

$\endgroup$
4
  • $\begingroup$ In mathematica, like in other languages (or very most of them), there is a clear distinction beetween integer (i) and string ("blabla"). If you multiply a string by a integer, you don't obtain a string. Hence your question sounds extra-terrest. $\endgroup$
    – andre314
    Commented Aug 2, 2018 at 13:56
  • $\begingroup$ A bit of an extrapolation, but also check out Indexed Variables for these things. $\endgroup$
    – Musang
    Commented Aug 2, 2018 at 15:38
  • 1
    $\begingroup$ Some related: (3165), (21109), (48315), (60680), (73135), (118658). See StringTemplate[] in addition to ToString. $\endgroup$
    – Michael E2
    Commented Aug 2, 2018 at 19:49
  • $\begingroup$ Also related, or duplicate: 176419, 36886, and see How to print an integer with n leading zeros in Mathematica on SO. $\endgroup$
    – user1066
    Commented Aug 2, 2018 at 20:30

1 Answer 1

3
$\begingroup$
Table["x" <> ToString[i], {i, 5}]

{"x1", "x2", "x3", "x4", "x5"}

$\endgroup$
1
  • $\begingroup$ That was clever, thank you loads gonna accept this :) $\endgroup$
    – Wiliam
    Commented Aug 2, 2018 at 13:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.