1

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Bipolar Minds
  • 265
  • 1
  • 6
  • 2
    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?: https://mathematica.stackexchange.com/q/10582/1871 – xzczd Mar 27 '20 at 09: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] – Bipolar Minds Mar 27 '20 at 09: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. – xzczd Mar 27 '20 at 09: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? – Bipolar Minds Mar 27 '20 at 09:34
  • Of course, another option is to transport the matrix A=sym('A',[m,n]) from Matlab somehow to Mathematica (maybe this is what you meant), but I don't know how either – Bipolar Minds Mar 27 '20 at 09:38
  • Is the equation system linear? If so, you can use LinearSolve. – xzczd Mar 27 '20 at 09:50
  • unfortunately not – Bipolar Minds Mar 27 '20 at 09:53
  • 2
    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. – xzczd Mar 27 '20 at 09:55
  • yes, this is exactly what I wanted to do. And yes, this is a problem indeed – Bipolar Minds Mar 27 '20 at 10:02
  • "…because it's the short form of built-in function Pattern" Oops, precisely speaking, it should be "FullForm of e.g. Ai_j is Pattern[Ai, Blank[j]]". – xzczd Mar 27 '20 at 11:19

1 Answers1

2

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}]