# Create table A with entries of the form Ai_j

I would like to create an $$m \times n$$-table A with entries Ai_j, where $$1 \leq i \leq m$$ and $$1 \leq j \leq n$$. I have seen similar questions with subscripts, but I need the entries to be exactly of the form Ai_j, since I'm importing data from MatLab.

To be more specific, I have a list of equations with variables Ai_j from Matlab and I want to solve them with Mathematica. For this I need to specify for which variables to solve, but I'm to lazy to type them in one-for-one (its a huge matrix) so I just wanted to use Flatten[A].

As written in the comments, another option would be to transport the matrix A=sym('A',[m,n]) from Matlab to Mathematica, but I don't know how either.

• What do you mean by "I need the entries to be exactly of the form Ai_j, since I'm importing data from MatLab"? Please be more specific. BTW, since you mentioned MATLAB, are you aware of this issue?: mathematica.stackexchange.com/q/10582/1871 Mar 27 '20 at 9:23
• I have a list of equations with variables Ai_j from Matlab and I want to solve them with Mathematica. For this I need to specify for which variables to solve, but I'm to lazy to type them in one-for-one (its a huge matrix) so I just wanted to use Flatten[A] Mar 27 '20 at 9:23
• …Well, if I understand correctly, you don't know Part ([[]]) can be used on multi-dimensional lists, too? If so, an example: mat={{1,2},{4,5}}; mat[[2, 1]]. Please check the document of Part for more info. Mar 27 '20 at 9:27
• No, I give you an example. Given an equation 4*A3_5 +8*A7_9==0, I would like to solve it for {A3_5,A7_9}. Now, I have a large number of much more complicated equations in variables Ai_j. So, how to effectively specify the list of variables in Solve? Mar 27 '20 at 9:34
• Do you mean you're importing symbolic expressions like Ai_j from MATLAB? If so, a more severe problem is, you cannot use _ for variable naming in Mathematica, because it's the short form of built-in function Pattern. Mar 27 '20 at 9:55

Does the below code suffice?

{m, n} = {3, 5};
Array[Subscript[Symbol["A" <> ToString[#]], #2] &, {m, n}]


Update

Now that it has been figured out how to generate symbols without underscores in MATLAB, I provide a Wolfram version here:

Array[Symbol[StringTemplate["A"][##]] &, {m, n}]

• Unfortunately not, because of the subscript, but as xzczd pointed out in the comments of the OP, what I wanted doesn't work Mar 27 '20 at 10:07
• @BipolarMinds Do you mean to let underscores (_) appear in the symbols? Mar 27 '20 at 10:10
• yes, appareantly this is not allowed for variables Mar 27 '20 at 10:13
• @BipolarMinds OK, it looks like you have learned about it. So I suggest you import those variables as Strings and then delete (e.g., using StringDelete) the underscore characters before converting them into Symbols, so that you will have "Ai_j" $\rightarrow$ "Aij" $\rightarrow$ Aij. Mar 27 '20 at 10:16
• @BipolarMinds Ah, it turns out to be A = sym('A%d%d', [3, 5]) in MATLAB. Mar 27 '20 at 10:44