Skip to main content
added 417 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Perhaps I'm missing some subtlety of the question but it seems to me that you could merely do:

MapIndexed[
 Subscript[x, #, #2[[1]]] &,
 {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}
]

$\left\{x_{\text{tem},1},x_{\text{pressure},2},x_{\text{hum},3},x_{\text{lat},4},x_{\text{alt},5},x_{\text{space},6},x_{\text{corner},7}\right\}$


I failed to understand your original quesiton, but looking at the update here is another section of code that produces the same output. Whether or not it is better I don't know.

Outer[
  Subscript[x, ##] & @@ Subscript @@@ Partition[{##}, 2] &,
  {"a", "b"}, {1, 2, 3, 4}, {"i", "j"}, {1, 2, 3, 4}, {"m", "n"},
   {1, 2}, {"A", "B", "C", "D"}, {1, 2, 3, 4, 5, 6, 7}
]

Perhaps I'm missing some subtlety of the question but it seems to me that you could merely do:

MapIndexed[
 Subscript[x, #, #2[[1]]] &,
 {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}
]

$\left\{x_{\text{tem},1},x_{\text{pressure},2},x_{\text{hum},3},x_{\text{lat},4},x_{\text{alt},5},x_{\text{space},6},x_{\text{corner},7}\right\}$

Perhaps I'm missing some subtlety of the question but it seems to me that you could merely do:

MapIndexed[
 Subscript[x, #, #2[[1]]] &,
 {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}
]

$\left\{x_{\text{tem},1},x_{\text{pressure},2},x_{\text{hum},3},x_{\text{lat},4},x_{\text{alt},5},x_{\text{space},6},x_{\text{corner},7}\right\}$


I failed to understand your original quesiton, but looking at the update here is another section of code that produces the same output. Whether or not it is better I don't know.

Outer[
  Subscript[x, ##] & @@ Subscript @@@ Partition[{##}, 2] &,
  {"a", "b"}, {1, 2, 3, 4}, {"i", "j"}, {1, 2, 3, 4}, {"m", "n"},
   {1, 2}, {"A", "B", "C", "D"}, {1, 2, 3, 4, 5, 6, 7}
]
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

Perhaps I'm missing some subtlety of the question but it seems to me that you could merely do:

MapIndexed[
 Subscript[x, #, #2[[1]]] &,
 {"tem", "pressure", "hum", "lat", "alt", "space", "corner"}
]

$\left\{x_{\text{tem},1},x_{\text{pressure},2},x_{\text{hum},3},x_{\text{lat},4},x_{\text{alt},5},x_{\text{space},6},x_{\text{corner},7}\right\}$